Win a copy of The Little Book of Impediments (e-book only) this week in the Agile and Other Processes forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Help with this error PLEASE!!!!!

 
JeF Ald
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
i am just learning jdbs and i created a test db in access and below is the error that i get
java.sql.SQLException: [Microsoft][ODBC Driver Manager] Invalid cursor state
this is the code that creates the error
try
{
String strNumber = "124";
Statement cmdEmployees = conEmployees.createStatement();
ResultSet rsEmployees =
cmdEmployees.executeQuery("Select * from employees where ssn= '"+strNumber+"';");

lblOutput.setText(rsEmployees.getString("firstName"));

conEmployees.close();
}
catch(SQLException sqlError)
{
System.out.println("sqlException Error::: ");
System.out.println(sqlError + "\n");


}
i cannot figer out what is going on with this also the program is not loading the microsoft driver it loads the sun driver WHY? this is a Accss XP database here is the code below for that

try
{
Class.forName("com.ms.jdbc.odbc.Jdbc0dbcDriver");

}
catch(ClassNotFoundException error)
{

System.out.println("Could not load Microsoft driver::: " + error + "\n");

try
{
//load sun drivers
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
System.out.println("\n Loaded sun driver::: \n");
}
catch(ClassNotFoundException err)
{
System.out.println("Sun Driver did not load properly" + err + "\n");


}


}
 
Bosun Bello
Ranch Hand
Posts: 1511
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Invalid cursor state is caused by the fact that when your resultset is created you are positioned before the first row. You have to do yourResultSet.next() to move to the first row. if you plan on processing all rows in the resultset, use a while loop as in
while(yourResultSet.next(){
do whatever...
}
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic