Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 3 of 3

Thread: could anybody fix my problem? resultset is closed

  1. #1
    Junior Member
    Join Date
    Apr 2012
    Posts
    2
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default could anybody fix my problem? resultset is closed

    hello guys, i am new in java
    could anyone help me with it? thanks before

    here is my code:

    String password = txPass.getText();
        String username = txUsername.getText(); 
     
        //int username1 = Integer.parseInt(username);
        //Double username1 = Double.parseDouble(username);
     
     
     
            try
            {
                String dbname="jdbc:odbc:Database";
                Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
                Connection con = DriverManager.getConnection(dbname,"admin","admin");
                Statement s = con.createStatement();
                String sql = "SELECT * FROM admin where Username ='"+username+"' AND Password = '"+password+"' " ;
     
     
                ResultSet rs = s.executeQuery(sql);
     
     
                if (rs.next())
                {
                    //throw new Exception();
                    JOptionPane.showMessageDialog(null, "Login Sukses", "INFO", JOptionPane.INFORMATION_MESSAGE);
     
                    Menu_admin admin = new Menu_admin();
                    admin.setVisible(true);
                    admin.setUser(rs.getString(1));
                    dispose();
                    //setVisible(false);
                    //new Menu_admin().setVisible(true);
                    rs.getStatement().close();
     
                } 
     
                else
                {
                    try
                    {
                        //Statement s = con.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE,ResultSet.CONCUR_UPDATABLE);
                        String skl = "SELECT* FROM mahasiswa where NIM ='"+username+"' AND password = '"+password+"' " ;
                        ResultSet rk = s.executeQuery(skl);
     
                        if (rk.next())
                        {
                            JOptionPane.showMessageDialog(null, "Login Sukses", "INFO", JOptionPane.INFORMATION_MESSAGE);
     
                            Menu_mhs mhs = new Menu_mhs();
                            mhs.setVisible(true);
                            mhs.setMhs(rs.getString(1));
                            dispose();
                            //new Menu_dsn().setVisible(true);
     
                        }
     
     
                        else
                        {
                            try
                            {
                                Statement b = con.createStatement();
                            String sjl = "SELECT* FROM dosen where NID ='"+username+"' AND password = '"+password+"' " ;
                            ResultSet rj = b.executeQuery(sjl);
     
                            if (rj.next())
                                {
                                    JOptionPane.showMessageDialog(null, "Login Sukses", "INFO", JOptionPane.INFORMATION_MESSAGE);
     
                                    Menu_dsn dsn = new Menu_dsn();
                                    dsn.setVisible(true);
                                    dsn.setUser(rs.getString(1));
                                    dispose();
                                    //new Menu_mhs().setVisible(true);
                                }
     
                            else
                                {
                                    JOptionPane.showMessageDialog(null, "Username atau Password salah", "ERROR", JOptionPane.ERROR_MESSAGE);
                                }                                             
                            }
     
                            catch (Exception e)
                            {
                               JOptionPane.showMessageDialog(null,"Error:\n" +e,"ERROR",JOptionPane.WARNING_MESSAGE);            
                            }
                        }
                    }
     
                    catch (Exception e)
                    {
                        JOptionPane.showMessageDialog(null,"Error:\n" +e,"ERROR",JOptionPane.WARNING_MESSAGE);                          
                    }
                }
     
     
     
            }
            catch (Exception e)
            {
                JOptionPane.showMessageDialog(null,"Error:\n" +e,"ERROR",JOptionPane.WARNING_MESSAGE);
              // new Menu().setVisible(true);
            }
    Last edited by kagami; April 18th, 2012 at 07:25 AM.


  2. #2
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    22,260
    Thanks
    56
    Thanked 2,372 Times in 2,343 Posts

    Default Re: could anybody fix my problem? resultset is closed

    You should always call the printStackTrace() method in the catch blocks to get the full text of the error messages so you can see exactly what and where the exception is.
    If you don't understand my answer, don't ignore it, ask a question.

  3. The Following User Says Thank You to Norm For This Useful Post:

    kagami (April 18th, 2012)

  4. #3
    Junior Member
    Join Date
    Apr 2012
    Posts
    2
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default Re: could anybody fix my problem? resultset is closed

    Quote Originally Posted by Norm View Post
    You should always call the printStackTrace() method in the catch blocks to get the full text of the error messages so you can see exactly what and where the exception is.
    OK.. thanks Norm for ur help
    my problem is solved right now

    the problem came in this line ya
    if (rk.next())
                        {
                            JOptionPane.showMessageDialog(null, "Login Sukses", "INFO", JOptionPane.INFORMATION_MESSAGE);
     
     
                            Menu_mhs mhs = new Menu_mhs();
                            mhs.setMhs(rs.getString(1));     //i just forgot change rs to rk
                            mhs.setVisible(true);
     
                            dispose();
                            //new Menu_dsn().setVisible(true);
     
                        }
    just because of that i had wasting time for 5 hours
    haha. .

Similar Threads

  1. Result set is closed
    By keshav_agrawal89 in forum What's Wrong With My Code?
    Replies: 6
    Last Post: June 11th, 2011, 09:35 AM
  2. Resultset for relate table
    By whiga in forum JDBC & Databases
    Replies: 1
    Last Post: May 16th, 2011, 02:04 PM
  3. ResultSet issues
    By _lithium_ in forum JDBC & Databases
    Replies: 3
    Last Post: March 4th, 2011, 03:20 PM
  4. Replies: 3
    Last Post: January 5th, 2011, 08:12 AM
  5. ResultSet is Closed
    By ramayya4u in forum JavaServer Pages: JSP & JSTL
    Replies: 1
    Last Post: May 24th, 2009, 04:54 AM