我想将收到的计数值存储到变量计数中,然后可以将其附加到字符串以准备客户 ID,但它给了我光标无效错误。请看下面并帮助我。提前致谢。:)
**package components;
import java.awt.geom.GeneralPath;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
public class genrateid {
public void generateid(){
int count;
try {
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
Connection conn = DriverManager.getConnection("jdbc:odbc:XE",
"system", "tiger");
System.out.println("Connection Successfull");
System.out.println(conn);
//--------------------------------------------------------------------
Statement stmt = conn.createStatement();
String query1= "select count(*) as customercount from customers";
ResultSet rs= stmt.executeQuery(query1);
count = rs.getInt(1);
} catch (ClassNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
public static void main(String[] args) {
genrateid gen = new genrateid();
gen.generateid();
}
}**
I am receiving the following error in in eclipse IDE:
输出:
Connection Successfull
sun.jdbc.odbc.JdbcOdbcConnection@39b27b
java.sql.SQLException: [Microsoft][ODBC Driver Manager] Invalid cursor state
at sun.jdbc.odbc.JdbcOdbc.createSQLException(Unknown Source)
at sun.jdbc.odbc.JdbcOdbc.standardError(Unknown Source)
at sun.jdbc.odbc.JdbcOdbc.SQLGetDataInteger(Unknown Source)
at sun.jdbc.odbc.JdbcOdbcResultSet.getDataInteger(Unknown Source)
at sun.jdbc.odbc.JdbcOdbcResultSet.getInt(Unknown Source)
at components.genrateid.generateid(genrateid.java:29)
at components.genrateid.main(genrateid.java:43)