By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
448,584 Members | 1,065 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 448,584 IT Pros & Developers. It's quick & easy.

JDBC error

P: 25
Hi Guy, I am using a JDBC connection to retrieve data and populate datasets. Having some problems with errors:
Error: java.sql.SQLException: [Microsoft][ODBC Driver Manager] Invalid cursor state

Expand|Select|Wrap|Line Numbers
  1.           // now we can get the connection from the DriverManager
  2.             Connection con = DriverManager.getConnection(database ,"","");
  3.  
  4.                 //String searchPatients = G.PatientSearch.getText();
  5.  
  6.             // We are connected, so lets create a statement to ask for names from our table "names"
  7.             Statement s = con.createStatement();
  8.             Statement s2 = con.createStatement();
  9.  
  10.  
  11.             s.execute("select Username  from Usernames");
  12.             s2.execute("select Password from Usernames");
  13.  
  14.             // Execute and get the results
  15.  
  16.             //rs2 is to get the Ward of the patient
  17.             ResultSet rs = s.getResultSet();// Patient Name Verification
  18.             ResultSet rs2 = s2.getResultSet(); // Ward name
  19.  
  20.             if (rs != null) {
  21.                 // If we had results, loop through them...
  22.                 while ( rs.next() )
  23.                 {
  24.  
  25.  
  26.  
  27.                    // resultset1 = rs.getString(1);
  28.                String RS2,strUsername, strPassword;
  29.  
  30.                 RS1 = rs.getString("Username" );
  31.                  RS2 = rs2.getString("Password" );
  32.                  strUsername = txtUsername.getText();
  33.                  strPassword = txtPassword.getText();
  34.  
  35.                 //SearchString = txtSearch.getText();
  36.                 int rowNum;
  37.                 int rowFind;
  38.  
  39.  
  40.  
  41.  
  42.                     // Just prints out the values
  43.                   if(RS1.equals(strUsername))// Filters by Name
  44.                  {
  45.                   //First check that the name is on the list
  46.                     System.out.println(strUsername);// rints the name
  47.  
  48.                  //  int rowrs1 =  rs.getRow();// Get the row number of the successful entry
  49.  
  50.                    // the next part gets the Ward of the patient
  51.                    // all depending on the row number of the first condition set
  52.                    // with rs - the first result set.
  53.                    // I got the row number of the set then
  54.                    // when rs2 cycles through the database, if its row number
  55.                    // is equal to the row number of the first rs - row number successful search
  56.                    // it will print the details, eg ward and later on the room number
  57.  
  58.                   // int rowrs3 =  rs3.getRow();// gets the row number of the 3rd result set
  59.                   // while ( rs2.next() )
  60.  
  61.                    //                 {
  62. //                     System.out.println("success");
  63.  
  64.                     //                }// end of rs3 While statement
  65.                   } //end of if on result set1 Name Filter
  66.  
  67.  
  68.  
  69.  
  70.                 }
  71.             }
  72.  
  73.             // Cleanup our statement and connection by closing them.
  74.             s.close();
  75.             con.close();
  76.         }
  77.  
  78.         // If there was an error connection or querying, show the error.
  79.         catch (Exception e) {
  80.             System.out.println("Error: " + e);
  81.         }
  82.  
  83.  
  84.  
  85.  
  86.  
  87.     return null;
  88.  
  89.     }
  90.  
Maybe there is something I am missing. any help would be greatly appreciated.
Mar 22 '09 #1
Share this Question
Share on Google+
2 Replies


Expert 10K+
P: 11,448
Make your code print out the complete stack trace; it contains line numbers and all; in your catch clause do this:

Expand|Select|Wrap|Line Numbers
  1. e.printStackTrace();
  2.  
... so you can see where exactly that exception was thrown.

kind regards,

Jos
Mar 22 '09 #2

P: 25
Thanks Jos,
I'll implement that right away :)
Mar 22 '09 #3

Post your reply

Sign in to post your reply or Sign up for a free account.