我在这里看到了很多指南,上面写着
if (!res.next())
应该检查语句是否为空,但是当我这样做时,我收到此错误
org.apache.jasper.JasperException: An exception occurred processing JSP page /irasyti.jsp at line 73
70: String rezervbusena=""; // rezervo busenos info
71: String uzsakymas=""; // uzsakymas info
72:
73: if( !res.next()){ //jei kambariai neuzimti
74: try {
我不知道出了什么问题;也许我需要导入一些实用程序? :/我的代码:
ResultSet res = null;
Statement stmt = null;
try {
stmt = connection.createStatement();
//res=stmt.executeQuery
String tas=("SELECT * from table");
res=stmt.executeQuery(tas);
out.println("<br>tas: "+tas + "<br>");
}catch(Exception ex){
out.println("Klaida skaityme: "+ex);
}
if( !res.next()){ //jei kambariai neuzimti
try {}
catch(Exception ex){
out.println("error: "+ex);
}
}
错误是res结果集为空,并且在mysql返回空语句后它仍然为空,所以我必须首先检查它是否为空if(res!=null)
谢谢大家的回答
最佳答案
您可以尝试使用以下代码并查看是否出现任何错误吗?
ResultSet res = null;
Statement stmt = null;
try {
stmt = connection.createStatement();
//res=stmt.executeQuery
String tas=("SELECT * from table");
res=stmt.executeQuery(tas);
out.println("<br>tas: "+tas + "<br>");
if(res.next()){ //jei kambariai neuzimti
out.println("rs value "+rs.getString(1);
}
}
catch(Exception e){
e.printStackTrace();
}
关于mysql - SQL语句为空错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12114680/