Results 1 to 7 of 7
  1. #1
    RefugeX is offline Member
    Join Date
    Dec 2011
    Posts
    6
    Rep Power
    0

    Default Problem with ResultSet when using GUI

    Hi I have this issue when the following line is executed
    Java Code:
    while ( rs.next() ) {
                   System.out.println(rs.getString("Profile_Name"));
                   System.out.println("TEST Im inside loop");          
                   
                }
    The scenario is when i click a button it calls a method where ResultSet is.
    here is the event:
    Java Code:
    public void actionPerformed(ActionEvent e) {
            Object source = e.getSource();
            
            if (source == List_Data){
                
               Session.RetrieveData();
                
             
            }
            
        }
    But what ends up happening is the while(rs1.next()) part is completely skipped.

    I have tried calling the method without any GUI involved, ex: object.callmethod();
    Without any GUI the while(rs1.next()) is being executed.

  2. #2
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    26

    Default Re: Problem with ResultSet when using GUI

    I'm not sure that you've posted enough code to allow us to decipher your problem.

  3. #3
    RefugeX is offline Member
    Join Date
    Dec 2011
    Posts
    6
    Rep Power
    0

    Default Re: Problem with ResultSet when using GUI

    Here are the two classes involved
    Basically I am just trying to verify at this point that when i click on the button while(rs1.next()) part is working

    Java Code:
    public class ManagerUI extends JFrame implements ActionListener {
        
        User Session;
        JButton List_Data;
        DefaultTableModel model;
        JTable table;
        JScrollPane scrollpane;
        
        public ManagerUI(String login, String pass) {
                  
            super("Password Manager"); setBounds(100,100,750,450);
            setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
            
            JPanel pmain = new JPanel();
            pmain.setLayout(new GridLayout(1,1,0,0));
            JPanel p1 = new JPanel();
            p1.setLayout(new BoxLayout(p1, BoxLayout.LINE_AXIS));
            p1.add(new JLabel("Session:  " +login+"    "));
            List_Data = new JButton("List Data");
            p1.add(List_Data);
            pmain.add(p1);
            
            
            
            
            Session = new User(login,pass);        
            model = new DefaultTableModel(Session.RetrieveColumns(),0);
            table = new JTable(model);
            scrollpane = new JScrollPane(table);
            
            
            List_Data.addActionListener(this);
            getContentPane().add(pmain,BorderLayout.NORTH);
            getContentPane().add(scrollpane,BorderLayout.CENTER);
            setVisible(true);
        }
    
        @Override
        public void actionPerformed(ActionEvent e) {
            Object source = e.getSource();
            
            if (source == List_Data){
                
               Session.RetrieveData();
                
             
            }
            
        }
        
        
    }

    Java Code:
    public class User {
        String URL ="jdbc:oracle:thin:@127.0.0.1:1521:TestDB";
        String DB_User="SCOTT";
        String DB_pwd="password123";
        String driverName = "oracle.jdbc.driver.OracleDriver";
        String User, Pass, Acc_ID;
        ArrayList myList = new ArrayList();
        
        
        public User(String User, String Pass) {
            this.User = User;
            this.Pass = Pass;
            this.Acc_ID="nothing";
            
        }
    
        public String getAcc_ID() {
            return Acc_ID;
        }
    
        public String getPass() {
            return Pass;
        }
    
        
        public String getUser() {
            return User;
        }
        
        public Boolean Authorized(){
            
            Boolean check = false;
            String passcheck="";
            String Log="";
            String AI="";
                  
            try {               
              
                Connection conn = DriverManager.getConnection(URL,DB_User,DB_pwd);
                Statement stmt = conn.createStatement();
                
                ResultSet rs;
                rs =stmt.executeQuery("Select * from ACCOUNTS where Login_ID ="+"'"+User+"'");
                
                
                while ( rs.next() ) {
                    Log = rs.getString("Login_ID");
                    passcheck = rs.getString("Pass_ID");
                    AI = rs.getString("Account_ID");
                                                                                   
                }
                
                conn.close();
                check = this.Pass.equals(passcheck);
                this.Acc_ID=AI;
               
                
            } catch (Exception e) {
                System.err.println("Got an exception! ");
                System.err.println(e.getMessage());
            }
           
            return check;
            
        }
        
        
        public String[] RetrieveColumns(){
            String[] colname=null;
            try {               
                
                Connection conn = DriverManager.getConnection(URL,DB_User,DB_pwd);
                Statement stmt = conn.createStatement();
                ResultSet rs;            
                rs =stmt.executeQuery("Select * from ACCOUNTS_DATA where ACCOUNT_ID ="+"'"+Acc_ID+"'");
                
                
                ResultSetMetaData rsMetaData = rs.getMetaData();
                colname= new String[rsMetaData.getColumnCount()];
                int numcol =rsMetaData.getColumnCount();
                
                for (int i = 1; i<numcol+1;i++){
                        colname[i-1]= rsMetaData.getColumnName(i);
                        //System.out.print(colname[i-1] + " ");
                }
                
               
                rs.close();
                stmt.close();
                conn.close();            
               // System.out.println(check);
                
            } catch (Exception e) {
                System.err.println("Got an exception! ");
                System.err.println(e.getMessage());
            }
            
            
            return colname;
        }
        
        
        
     public Vector RetrieveData(){
          Vector List = new Vector();  
          try {               
                
                Connection conn = DriverManager.getConnection(URL,DB_User,DB_pwd);
                Statement stmt1 = conn.createStatement();
                ResultSet rs1;            
                rs1 =stmt1.executeQuery("Select * from ACCOUNTS_DATA where ACCOUNT_ID ="+"'"+Acc_ID+"'");
               
                while (rs1.next()) {
           
                System.out.println(rs1.getString("PROFILE_NAME")); 
                System.out.println(rs1.getString("Im in the loop")); 
            
                }
                rs1.close();
                stmt1.close();
                conn.close();            
               
                
            } catch (Exception e) {
                System.err.println("Got an exception! ");
                System.err.println(e.getMessage());
            }
            
            
            return List;
        }   
     
     
     
        
    }

  4. #4
    RefugeX is offline Member
    Join Date
    Dec 2011
    Posts
    6
    Rep Power
    0

    Default Re: Problem with ResultSet when using GUI

    Here are the two classes involved


    Java Code:
    public class ManagerUI extends JFrame implements ActionListener {
        
        User Session;
        JButton List_Data;
        DefaultTableModel model;
        JTable table;
        JScrollPane scrollpane;
        
        public ManagerUI(String login, String pass) {
                  
            super("Password Manager"); setBounds(100,100,750,450);
            setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
            
            JPanel pmain = new JPanel();
            pmain.setLayout(new GridLayout(1,1,0,0));
            JPanel p1 = new JPanel();
            p1.setLayout(new BoxLayout(p1, BoxLayout.LINE_AXIS));
            p1.add(new JLabel("Session:  " +login+"    "));
            List_Data = new JButton("List Data");
            p1.add(List_Data);
            pmain.add(p1);
            
            
            
            
            Session = new User(login,pass);        
            model = new DefaultTableModel(Session.RetrieveColumns(),0);
            table = new JTable(model);
            scrollpane = new JScrollPane(table);
            
            
            List_Data.addActionListener(this);
            getContentPane().add(pmain,BorderLayout.NORTH);
            getContentPane().add(scrollpane,BorderLayout.CENTER);
            setVisible(true);
        }
    
        @Override
        public void actionPerformed(ActionEvent e) {
            Object source = e.getSource();
            
            if (source == List_Data){
                
               Session.RetrieveData();
                
             
            }
            
        }
        
        
    }
    Java Code:
    public class User {
        String URL ="jdbc:oracle:thin:@127.0.0.1:1521:TestDB";
        String DB_User="SCOTT";
        String DB_pwd="password123";
        String driverName = "oracle.jdbc.driver.OracleDriver";
        String User, Pass, Acc_ID;
        ArrayList myList = new ArrayList();
        
        
        public User(String User, String Pass) {
            this.User = User;
            this.Pass = Pass;
            this.Acc_ID="nothing";
            
        }
    
        public String getAcc_ID() {
            return Acc_ID;
        }
    
        public String getPass() {
            return Pass;
        }
    
        
        public String getUser() {
            return User;
        }
        
        public Boolean Authorized(){
            
            Boolean check = false;
            String passcheck="";
            String Log="";
            String AI="";
                  
            try {               
              
                Connection conn = DriverManager.getConnection(URL,DB_User,DB_pwd);
                Statement stmt = conn.createStatement();
                
                ResultSet rs;
                rs =stmt.executeQuery("Select * from ACCOUNTS where Login_ID ="+"'"+User+"'");
                
                
                while ( rs.next() ) {
                    Log = rs.getString("Login_ID");
                    passcheck = rs.getString("Pass_ID");
                    AI = rs.getString("Account_ID");
                                                                                   
                }
                
                conn.close();
                check = this.Pass.equals(passcheck);
                this.Acc_ID=AI;
               
                
            } catch (Exception e) {
                System.err.println("Got an exception! ");
                System.err.println(e.getMessage());
            }
           
            return check;
            
        }
        
        
        public String[] RetrieveColumns(){
            String[] colname=null;
            try {               
                
                Connection conn = DriverManager.getConnection(URL,DB_User,DB_pwd);
                Statement stmt = conn.createStatement();
                ResultSet rs;            
                rs =stmt.executeQuery("Select * from ACCOUNTS_DATA where ACCOUNT_ID ="+"'"+Acc_ID+"'");
                
                
                ResultSetMetaData rsMetaData = rs.getMetaData();
                colname= new String[rsMetaData.getColumnCount()];
                int numcol =rsMetaData.getColumnCount();
                
                for (int i = 1; i<numcol+1;i++){
                        colname[i-1]= rsMetaData.getColumnName(i);
                        //System.out.print(colname[i-1] + " ");
                }
                
               
                rs.close();
                stmt.close();
                conn.close();            
               // System.out.println(check);
                
            } catch (Exception e) {
                System.err.println("Got an exception! ");
                System.err.println(e.getMessage());
            }
            
            
            return colname;
        }
        
        
        
     public Vector RetrieveData(){
          Vector List = new Vector();  
          try {               
                
                Connection conn = DriverManager.getConnection(URL,DB_User,DB_pwd);
                Statement stmt1 = conn.createStatement();
                ResultSet rs1;            
                rs1 =stmt1.executeQuery("Select * from ACCOUNTS_DATA where ACCOUNT_ID ="+"'"+Acc_ID+"'");
               
                while (rs1.next()) {
           
                System.out.println(rs1.getString("PROFILE_NAME")); 
                System.out.println("Im in the loop");
            
                }
                rs1.close();
                stmt1.close();
                conn.close();            
               
                
            } catch (Exception e) {
                System.err.println("Got an exception! ");
                System.err.println(e.getMessage());
            }
            
            
            return List;
        }   
     
     
     
        
    }

  5. #5
    RefugeX is offline Member
    Join Date
    Dec 2011
    Posts
    6
    Rep Power
    0

    Default Re: Problem with ResultSet when using GUI

    Not sure why but im trying to post the classes but my post isnt showing up.
    Last edited by RefugeX; 12-01-2011 at 10:35 PM.

  6. #6
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    26

    Default Re: Problem with ResultSet when using GUI

    You're new here and so posts with code or links need to be approved -- which I have done.

    So any error messages when the button is pressed? Does the GUI freeze up? Anything on the console? What happens?

  7. #7
    RefugeX is offline Member
    Join Date
    Dec 2011
    Posts
    6
    Rep Power
    0

    Default Re: Problem with ResultSet when using GUI

    no there are no errors shown.
    That is why i find it odd because when I call the RetrieveData() method from my main class without any GUI.
    The
    while (rs1.next()) {}
    section is executed normally.

Similar Threads

  1. Problem while retrieving column size of ResultSet
    By gurrapuk in forum Advanced Java
    Replies: 5
    Last Post: 04-11-2011, 04:52 PM
  2. Problem with ResultSet
    By flaquitqm in forum JDBC
    Replies: 8
    Last Post: 01-27-2010, 08:49 AM
  3. Replies: 4
    Last Post: 04-01-2009, 02:03 AM
  4. ResultSet.updateRow() problem
    By kvikas in forum Advanced Java
    Replies: 1
    Last Post: 04-22-2008, 03:11 AM
  5. problem with ResultSet.updateRow()
    By kvikas in forum New To Java
    Replies: 0
    Last Post: 04-14-2008, 10:00 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
  •