gpt4 book ai didi

Java - 从MySQL获取乱码结果(列表)

转载 作者:行者123 更新时间:2023-11-29 13:02:38 25 4
gpt4 key购买 nike

结果应类似于[1,2,3,4],但我得到这样的乱码结果

[com.test.db.Network@383c7b61, com.test.db.Network@7f87898,
com.test.db.Network@6b93f47a, com.test.db.Network@50fb09cc]

下面是我的相关类(class)

private static void doLocationList(PrintWriter responseOut) throws Exception
{
//---testing show network ID list
int x=0;
Network network = new Network();
responseOut.println("this is I: " +network.getNetworkID(x));

......
}

这是来自另一个类(class)

public static List<Network> getNetworkID(int networkID) throws Exception
{
List<Network> idList = new ArrayList<Network>();
Connection conn = getConnection();
PreparedStatement Statement = conn.prepareStatement("Select id from network");
ResultSet result = Statement.executeQuery();
while(result.next()) {
Network network = new Network();
network.setId(result.getInt("id"));
idList.add(network);
}

return idList;
}

有什么想法吗?请帮忙。

最佳答案

如果要直接打印对象列表,则需要重写Network类中的toString()方法,并指定在直接打印该类的对象。

默认的toString()方法如Object class docs.所示看看this post about toString()

关于Java - 从MySQL获取乱码结果(列表),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23124576/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com