【发布时间】:2018-04-19 14:33:49
【问题描述】:
我尝试使用 java Web 服务 SOAP REQUEST 从 mysql 数据库中获取数据并存储在 Arraylist 中。但是我的方法返回输出是这样的 java.util.List : "[chat.in.server.com.ThreadsClass@17b91ad3
ThreadClass 是处理线程信息的类。线程意味着消息
线程类
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 网络服务类
@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;
}
}
【问题讨论】:
-
如果您能处理异常并至少打印堆栈跟踪,那就太好了。没有它,我们和你一样对可能出现的问题视而不见。
-
@LuiggiMendoza 先生,我没有收到任何错误。我放了代码来捕获堆栈跟踪。但我不知道这是捕获堆栈跟踪的正确方法。
-
} catch (Exception e) { e.printStackTrace(new PrintStream(System.out)); }
-
先生,我没有收到任何错误你不知道,因为你有
catch (Exception e) { /* nothing is done here */ }。你至少应该有e.printStacktrace(System.out);知道你是否真的有例外。 -
我做到了,先生。但也不例外。 @LuiggiMendoza
标签: java mysql web-services soap