Results 1 to 9 of 9
  1. #1
    Join Date
    Jun 2010
    Posts
    17
    Rep Power
    0

    Thumbs down Connection is busy with results for another hstmt

    i got Problem in following code..


    try {
    enteruser = t4.getText();
    enterpass = t1.getText();
    newpass = t2.getText();
    confirm = t3.getText();
    PreparedStatement ps3 = con.prepareStatement("select * from sreg where username=?");
    ps3.setString(1, enteruser);
    ResultSet rs1 = ps3.executeQuery();
    rs1.next();
    getuser = rs1.getString(4);
    getuser=getuser.trim();
    getpass = rs1.getString(12);
    getpass=getpass.trim();
    System.out.println(getuser);
    System.out.println(getpass);
    System.out.println(enteruser);

    if (enteruser.equals(getuser)) {
    System.out.println(enterpass);


    if (enterpass.equals(getpass)) {

    PreparedStatement ps4 = con.prepareStatement("update sreg set choosepassword=?,repeatpassword=? where username=?");

    ps4.setString(3, enteruser);
    ps4.setString(1, newpass);
    ps4.setString(2, confirm);

    System.out.println(newpass);
    ps4.executeUpdate(); /* I hope this is not working


    System.out.println(confirm);
    JOptionPane.showMessageDialog(this, "Successfully Updated");
    } else {
    JOptionPane.showMessageDialog(this, "Please Enter Correct Current Password");
    }
    } else {
    JOptionPane.showMessageDialog(this, "Please Enter Correct Username");
    }
    } catch (SQLException ex) {
    Logger.getLogger(password.class.getName()).log(Lev el.SEVERE, null, ex);
    }





    Everytime i run it ,it give error connection is busy..and is unable to update a table..
    Somebody help please?

    Thanks in Advance
    Last edited by amritpalpathak; 07-17-2010 at 05:40 AM.

  2. #2
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,519
    Blog Entries
    7
    Rep Power
    20

    Default

    Quote Originally Posted by amritpalpathak View Post
    ps4.executeUpdate(); /*This is not working
    What happens if you close the ResultSet rs1 first?

    kind regards,

    Jos

  3. #3
    Join Date
    Jun 2010
    Posts
    17
    Rep Power
    0

    Default

    After removing the line
    ResultSet rs1 = ps3.executeQuery();

    It gives error in following code,because its object rs1 is being used in these

    rs1.next();
    getuser = rs1.getString(4);
    getpass = rs1.getString(12);




    Thannks

  4. #4
    Join Date
    Jun 2010
    Posts
    17
    Rep Power
    0

    Default

    System.out.println(newpass);
    ps4.executeUpdate();

    /*I hope this line is not working because new pass in coming in output but confirm not there,it means ps4.executeUpdate(); not working ,but why i d ont know reason,everything in the code in write ,i have checked i hundred of times

    System.out.println(confirm);


    Please Something solve this issue

  5. #5
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,519
    Blog Entries
    7
    Rep Power
    20

    Default

    Quote Originally Posted by amritpalpathak View Post
    After removing the line
    ResultSet rs1 = ps3.executeQuery();

    It gives error in following code,because its object rs1 is being used in these

    rs1.next();
    getuser = rs1.getString(4);
    getpass = rs1.getString(12);
    Nonono, that's not what I mean: after you got the data from rs1, close it by doing this:

    Java Code:
    rs1.close();
    ... and next execute your other PreparedStatement for its update.

    kind regards,

    Jos

  6. #6
    Join Date
    Jun 2010
    Posts
    17
    Rep Power
    0

    Default

    I did exectly as u said ,i add rs1.close() line as following


    getpass=getpass.trim();
    rs1.close();

    but still the same warning is there and table didnt update.

  7. #7
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,519
    Blog Entries
    7
    Rep Power
    20

    Default

    Quote Originally Posted by amritpalpathak View Post
    I did exectly as u said ,i add rs1.close() line as following


    getpass=getpass.trim();
    rs1.close();

    but still the same warning is there and table didnt update.
    Then also close your PreparedStatement ps3 after you have closed the ResultSet rs1.

    kind regards,

    Jos

  8. #8
    Join Date
    Jun 2010
    Posts
    17
    Rep Power
    0

    Default

    It done successfully
    I close both statements as
    rs1.close();
    ps3.close();

    Thank you very much joyAH,You have solved my problem,now its going well

    One thing more ,please tell me without closeing these both ,why it was not working and giving the error of "connection is busy"


    Regards
    Amrit pal pathak

  9. #9
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,519
    Blog Entries
    7
    Rep Power
    20

    Default

    Quote Originally Posted by amritpalpathak View Post
    It done successfully
    I close both statements as
    rs1.close();
    ps3.close();

    Thank you very much joyAH,You have solved my problem,now its going well

    One thing more ,please tell me without closeing these both ,why it was not working and giving the error of "connection is busy"


    Regards
    Amrit pal pathak
    In your second (update) PreparedStatement you alter your table 'sreg' that can potentially change the ResultSet in your first PreparedStatement. I would've expected that by releasing the ResultSet (by closing it) it would've removed that dependency, but apparently you need to close the entire PreparedStatement ... Check the different forms of prepareStatement( ... ) in the Connection interface; it should be possible to create one and have its ResultSet altered by another PreparedStatement ...

    kind regards,

    Jos

Similar Threads

  1. Java.net.socket connection :connection closed
    By veeru541 in forum Advanced Java
    Replies: 2
    Last Post: 06-27-2010, 02:14 AM
  2. Output to results file help!
    By javanator in forum New To Java
    Replies: 6
    Last Post: 04-18-2010, 01:59 AM
  3. Sometimes get the right results sometimes dont
    By Battlefeldt in forum New To Java
    Replies: 0
    Last Post: 12-18-2009, 01:03 AM
  4. how to take query results to a jlist!!
    By themburu in forum New To Java
    Replies: 3
    Last Post: 06-07-2008, 10:45 AM
  5. date and calender not getting the right results
    By valoyivd in forum New To Java
    Replies: 4
    Last Post: 04-14-2008, 11:51 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •