如何解决类型不匹配:无法从void转换为ArrayList <String> ||在JSP文件中使用Arraylist
获得了一个方法,该方法返回带有查询结果的ArrayList:
public ArrayList<String> answerRequest(String table,String attribut) {
ArrayList<String> res = new ArrayList<String>();
try (Statement st = getMySQLConnection().createStatement();) {
ResultSet daten = st.executeQuery("SELECT " + table + "." + attribut + " from " + table);
while (daten.next()) {
res.add(daten.getString(1));
}
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return res;
}
这工作正常,我在JSP文件中按以下方式调用该方法:
<%
ArrayList<String> res = new MySQLConnUtils().answerRequest("betreiber","name");
for (int i = 0; i < res.size(); i++) {
out.println(res.get(i));
}
%>
我得到了这个错误,但我没有落后,因为函数“ MySQLConnUtils()。answerRequest”显然返回一个数组...
An error occurred at line: [17] in the jsp file: [/TESTJSP.jsp]
Type mismatch: cannot convert from void to ArrayList<String>
14: <body>
15:
16: <%
17: ArrayList<String> res = new MySQLConnUtils().answerRequest("betreiber","name");
18: for (int i = 0; i < res.size(); i++) {
19: out.println(res.get(i));
20: }
感谢您的帮助!
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。