Click here to Skip to main content
15,893,368 members
Please Sign up or sign in to vote.
4.00/5 (1 vote)
See more:
Hello

I am trying to access a Microsoft acess database and i get the following error:
[Microsoft][ODBC Driver Manager] Invalid cursor state


My code is as following
import java.sql.*;


class Test
{
 public static void main(String[] args)
 {
 try {
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");

Connection con = DriverManager.getConnection("jdbc:odbc:Cont","","");
Statement s = con.createStatement();
ResultSet rset = s.executeQuery("SELECT * FROM Customer");
//ResultSet rset = s.getResultSet();

while(rset.next());
{
	System.out.exp.printStackTrace(rset.getString("ID") +" " + rset.getString("Name") +" " +
			rset.getString("Email") + " " +
			rset.getInt("Comments")); 
}

 }
 catch (ClassNotFoundException exp) {
System.err.println(exp);

 }
 catch(SQLException exp)
 {
	 System.err.println(exp);
 }
 }
}


Any help would be appreciated

Thanks
Posted
Updated 25-Jun-20 18:24pm

Take a look at this[^] thread where someone had the same error.

Note particularly the while loop and the couple of lines before it. (the beforefirst() call)

From this I have gathered that the cursor gets positioned past the end of the result set when the query is executed.
 
Share this answer
 
v2
Maybe can try this

Statement s = con.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE, ResultSet.CONCUR_READ_ONLY);
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900