Java搜索database时,出现 非法的游标状态 报错

flutina 2003-10-16 12:36:52
SQLException: [Microsoft][ODBC 驱动程序 管理器] 非法的游标状态

String url="jdbc:odbc:waterprocess";
String cs1="select Logical_Address, Colour from Display_Name where DisplayName='LT560'";
String cs2="select TimeInsert, Value from HISTORY_INFO where DateInsert = '"+date+ "' , Logical_Address='" +logical+ "' and TimeInert between " +timefrom +" and "+timeto+"'";

Connection con=null;
Statement stmt=null;
ResultSet rs =null;
try {
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
} catch(java.lang.ClassNotFoundException e) {
System.err.print("ClassNotFoundException:");
System.err.println(e.getMessage());
}


try {
con=DriverManager.getConnection(url);
stmt=con.createStatement();
rs= stmt.executeQuery(cs1);
//rs.next();
logical = rs.getString("Logical_Address");
color=rs.getString("Colour");

rs= stmt.executeQuery(cs2);

while(rs.next()) {


String time=rs.getDate("TimeInsert").toString();
String value = rs.getString("Logical_Address");
for(t=0;;t++){
result[t][0]=time;
result[t][1]=value;


}


}
stmt.close();
con.close();
}catch(SQLException ex) {
System.err.println("SQLException: "+ex.getMessage());
}


程序哪里出错了啊
...全文
42 2 打赏 收藏 转发到动态 举报
写回复
用AI写文章
2 条回复
切换为时间正序
请发表友善的回复…
发表回复
hiswing 2003-10-16
  • 打赏
  • 举报
回复
1 . cs2 的sql语句错了.仔细检查一下.
2 . rs.next();这句为什么注掉? 这样当然会出错.
3 . String time=rs.getDate("TimeInsert").toString();应当写成这样比较标准一些String.valueOf(rs.getDate("TimeInsert"));
4 . String value = rs.getString("Logical_Address");你的cs2的sql里面根本就没有Logical_Address这一项啊!!!
5 . for(t=0;;t++){
result[t][0]=time;
result[t][1]=value;
}
这是个死循环.
最后还是希望你有点专业精神,写程序一定要认真.记住:程序是写给人看的,不是让机器执行的.
yesemiman 2003-10-16
  • 打赏
  • 举报
回复
不好意思,拷贝的时候考成了之前的程序

但是这个非法游标的错误似乎不时程序造成的,因为以前能运行的关于数据库的程序突然也不能运行了,而且报同样的错误

可是我设置ODBC数据源没有改动过哦

62,612

社区成员

发帖
与我相关
我的任务
社区描述
Java 2 Standard Edition
社区管理员
  • Java SE
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧