例外。游标状态无效 [英] exception. invalid cursor state
本文介绍了例外。游标状态无效的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
请帮帮我我有异常(游标状态无效)我该怎么办?
please help me I have exception (invalid cursor state) what should I do ??
public void billnumber(){
try{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
Connection cn = DriverManager.getConnection("Jdbc:Odbc:ds_comboPractice");
Statement stmt = cn.createStatement();
rs = stmt.executeQuery("select max(Bill_Number) from combopractice");
int a = rs.getInt(1);
txt4.setText(String.valueOf(a));
}
catch (Exception ex){JOptionPane.showMessageDialog(this, ex.getMessage());
}
}
推荐答案
您是否正确创建了数据库?另外,你必须将用户名和密码放入网址。这是一个解决方案 http://stackoverflow.com/questions/17663167/ jdbc-driver-connection-problems-sun-jdbc-odbc-jdbcodbcdriver [ ^ ]
Have you created the database correctly? also, you have to put username and password to the url. Here is a solution http://stackoverflow.com/questions/17663167/jdbc-driver-connection-problems-sun-jdbc-odbc-jdbcodbcdriver[^]
问题在这里:
Problem is here :
int a = rs.getInt(1);
应该是这样的:
It should be like :
while(rs.next()){
int a = rs.getInt(1);
}
获取resultSet后,必须将结果集指针(光标)移动到第一行指向第一条记录。
After getting the resultSet, you have to move the result set pointer(cursor) to the first row to point the first record.
这篇关于例外。游标状态无效的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文