K
Kyle
I am going crazy trying to accomplish the simplest of tasks: retrieve
data via JDBC. I get a [Microsoft][ODBC Driver Manager] Invalid
cursor state SQLException whenever I access the Resultset.get*
methods. And, yes, I have remembered to call the .next() method
before the 1st access. I am using the JDBC-ODBC bridge and get the
same error with both Access and SQL Server databases. The query
executes and the Resultset exists as I can read the ResultSetMetaData
object and successfully read the number of columns and column names.
So, the problem definitely is in the fetching of the data.
Please embarass me and enlighten me as to what stupid mistake I am
making.
import java.sql.*;
public void runquery() {
ResultSet rs = null;
Statement sql_stmt = null;
Connection conn = null;
try {
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
conn = DriverManager.getConnection("jdbcdbc:LDXTables",
"sa", "");
sql_stmt = conn.createStatement();
sql_stmt.execute("SELECT * FROM testtable");
rs = sql_stmt.getResultSet();
if (rs!=null){
while (rs.next());
{
//ODBC Invalid cursor state error occurs on the
..getInt or .getString call
String str = String.valueOf(rs.getInt(1)) +
rs.getString(2) + "\n";
}
}
} catch (ClassNotFoundException ex) {
} catch (SQLException ex) {
} catch (Exception ex) {
} finally {
try {
rs.close();
} catch (SQLException ex) { }
try {
sql_stmt.close();
} catch (SQLException ex) { }
try {
conn.close();
} catch (SQLException ex) { }
}
}
data via JDBC. I get a [Microsoft][ODBC Driver Manager] Invalid
cursor state SQLException whenever I access the Resultset.get*
methods. And, yes, I have remembered to call the .next() method
before the 1st access. I am using the JDBC-ODBC bridge and get the
same error with both Access and SQL Server databases. The query
executes and the Resultset exists as I can read the ResultSetMetaData
object and successfully read the number of columns and column names.
So, the problem definitely is in the fetching of the data.
Please embarass me and enlighten me as to what stupid mistake I am
making.
import java.sql.*;
public void runquery() {
ResultSet rs = null;
Statement sql_stmt = null;
Connection conn = null;
try {
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
conn = DriverManager.getConnection("jdbcdbc:LDXTables",
"sa", "");
sql_stmt = conn.createStatement();
sql_stmt.execute("SELECT * FROM testtable");
rs = sql_stmt.getResultSet();
if (rs!=null){
while (rs.next());
{
//ODBC Invalid cursor state error occurs on the
..getInt or .getString call
String str = String.valueOf(rs.getInt(1)) +
rs.getString(2) + "\n";
}
}
} catch (ClassNotFoundException ex) {
} catch (SQLException ex) {
} catch (Exception ex) {
} finally {
try {
rs.close();
} catch (SQLException ex) { }
try {
sql_stmt.close();
} catch (SQLException ex) { }
try {
conn.close();
} catch (SQLException ex) { }
}
}