受け取ったカウント値を変数 count に格納し、それを文字列に追加して顧客 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)