I trying to get data from mysql database and store in the Arraylist using java web service SOAP REQUEST. But My method return output is like this java.util.List : "[chat.in.server.com.ThreadsClass@17b91ad3
我试图从mysql数据库获取数据并使用java Web服务SOAP REQUEST存储在Arraylist中。但我的方法返回输出就像这个java.util.List:“[chat.in.server.com.ThreadsClass@17b91ad3
ThreadClass is the class that handle Thread Information. Thread means Messages
ThreadClass是处理线程信息的类。线程意味着消息
How do I get real String data?
如何获得真正的String数据?
Thread Class
public class ThreadsClass {
private int id;
private String title;
private String author;
private String date;
public ThreadsClass() {
}
public ThreadsClass(int id,String title, String author, String date) {
this.id=id;
this.title = title;
this.author = author;
this.date = date;
}
public String getTitle() {
return title;
}
public String getAuthor() {
return author;
}
public String getDate() {
return date;
}
public int getId() {
return id;
}
}
Java web Services Class
@WebService(serviceName = "ChatHandle")
public class ChatHandle {
private Connection connection;
private Statement statement;
private ResultSet resultsSet;
private PreparedStatement prepStat;
@WebMethod(operationName = "displayThread")
public ArrayList<ThreadsClass> displayThread() {
ArrayList<ThreadsClass> threads = new ArrayList<>();
try {
Class.forName("com.mysql.jdbc.Driver");
connection = DriverManager.getConnection("jdbc:mysql://localhost:3306/chatapp", "root", "");
statement = connection.createStatement();
resultsSet = statement.executeQuery("select id,title, date, author from chatnew");
while (resultsSet.next()) {
ThreadsClass t = new ThreadsClass(
resultsSet.getInt("id"),
resultsSet.getString("title"),
resultsSet.getString("author"),
resultsSet.getString("date"));
threads.add(t);
}
} catch (Exception e) {
e.printStackTrace(new PrintStream(System.out));
}
return threads;
}
}
1 个解决方案
#1
0
Java prints instance hash codes as the default behavior for converting objects to strings. Try implementing toString()
in your ThreadsClass class:
Java打印实例哈希码作为将对象转换为字符串的默认行为。尝试在ThreadsClass类中实现toString():
@Override
public String toString(){
return "ThreadsClass: title = " + title + " author = " + author + " date = " + date + " id = " + id;
}
#1
0
Java prints instance hash codes as the default behavior for converting objects to strings. Try implementing toString()
in your ThreadsClass class:
Java打印实例哈希码作为将对象转换为字符串的默认行为。尝试在ThreadsClass类中实现toString():
@Override
public String toString(){
return "ThreadsClass: title = " + title + " author = " + author + " date = " + date + " id = " + id;
}