[英]How to get data from mysql databse using java web services?
I trying to get data from mysql database and store in the Arraylist using java web service SOAP REQUEST . 我试图使用Java Web服务SOAP REQUEST从mysql数据库获取数据并存储在Arraylist中。 But My method return output is like this java.util.List : "[chat.in.server.com.ThreadsClass@17b91ad3
但是我的方法返回的输出就像这样的java.util.List:“ [chat.in.server.com.ThreadsClass@17b91ad3
ThreadClass is the class that handle Thread Information. ThreadClass是处理线程信息的类。 Thread means Messages
线程表示消息
How do I get real String data? 如何获得真实的String数据?
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;
}
}
@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;
}
}
Java prints instance hash codes as the default behavior for converting objects to strings. Java将实例哈希码打印为将对象转换为字符串的默认行为。 Try implementing
toString()
in your ThreadsClass class: 尝试在ThreadsClass类中实现
toString()
:
@Override
public String toString(){
return "ThreadsClass: title = " + title + " author = " + author + " date = " + date + " id = " + id;
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.