Error: java.sql.SQLException: [Microsoft][ODBC Driver Manager] Invalid cursor state
Expand|Select|Wrap|Line Numbers
- // now we can get the connection from the DriverManager
- Connection con = DriverManager.getConnection(database ,"","");
- //String searchPatients = G.PatientSearch.getText();
- // We are connected, so lets create a statement to ask for names from our table "names"
- Statement s = con.createStatement();
- Statement s2 = con.createStatement();
- s.execute("select Username from Usernames");
- s2.execute("select Password from Usernames");
- // Execute and get the results
- //rs2 is to get the Ward of the patient
- ResultSet rs = s.getResultSet();// Patient Name Verification
- ResultSet rs2 = s2.getResultSet(); // Ward name
- if (rs != null) {
- // If we had results, loop through them...
- while ( rs.next() )
- {
- // resultset1 = rs.getString(1);
- String RS2,strUsername, strPassword;
- RS1 = rs.getString("Username" );
- RS2 = rs2.getString("Password" );
- strUsername = txtUsername.getText();
- strPassword = txtPassword.getText();
- //SearchString = txtSearch.getText();
- int rowNum;
- int rowFind;
- // Just prints out the values
- if(RS1.equals(strUsername))// Filters by Name
- {
- //First check that the name is on the list
- System.out.println(strUsername);// rints the name
- // int rowrs1 = rs.getRow();// Get the row number of the successful entry
- // the next part gets the Ward of the patient
- // all depending on the row number of the first condition set
- // with rs - the first result set.
- // I got the row number of the set then
- // when rs2 cycles through the database, if its row number
- // is equal to the row number of the first rs - row number successful search
- // it will print the details, eg ward and later on the room number
- // int rowrs3 = rs3.getRow();// gets the row number of the 3rd result set
- // while ( rs2.next() )
- // {
- // System.out.println("success");
- // }// end of rs3 While statement
- } //end of if on result set1 Name Filter
- }
- }
- // Cleanup our statement and connection by closing them.
- s.close();
- con.close();
- }
- // If there was an error connection or querying, show the error.
- catch (Exception e) {
- System.out.println("Error: " + e);
- }
- return null;
- }