Results 1 to 7 of 7
- 12-01-2011, 09:40 PM #1
Member
- Join Date
- Dec 2011
- Posts
- 6
- Rep Power
- 0
Problem with ResultSet when using GUI
Hi I have this issue when the following line is executed
The scenario is when i click a button it calls a method where ResultSet is.Java Code:while ( rs.next() ) { System.out.println(rs.getString("Profile_Name")); System.out.println("TEST Im inside loop"); }
here is the event:
But what ends up happening is the while(rs1.next()) part is completely skipped.Java Code:public void actionPerformed(ActionEvent e) { Object source = e.getSource(); if (source == List_Data){ Session.RetrieveData(); } }
I have tried calling the method without any GUI involved, ex: object.callmethod();
Without any GUI the while(rs1.next()) is being executed.
-
Re: Problem with ResultSet when using GUI
I'm not sure that you've posted enough code to allow us to decipher your problem.
- 12-01-2011, 10:07 PM #3
Member
- Join Date
- Dec 2011
- Posts
- 6
- Rep Power
- 0
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; } }
- 12-01-2011, 10:11 PM #4
Member
- Join Date
- Dec 2011
- Posts
- 6
- Rep Power
- 0
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; } }
- 12-01-2011, 10:12 PM #5
Member
- Join Date
- Dec 2011
- Posts
- 6
- Rep Power
- 0
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.
-
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?
- 12-01-2011, 10:21 PM #7
Member
- Join Date
- Dec 2011
- Posts
- 6
- Rep Power
- 0
Similar Threads
-
Problem while retrieving column size of ResultSet
By gurrapuk in forum Advanced JavaReplies: 5Last Post: 04-11-2011, 04:52 PM -
Problem with ResultSet
By flaquitqm in forum JDBCReplies: 8Last Post: 01-27-2010, 08:49 AM -
Problem when adding values of the ResultSet to a AbstractTableModel
By Azuxard in forum AWT / SwingReplies: 4Last Post: 04-01-2009, 02:03 AM -
ResultSet.updateRow() problem
By kvikas in forum Advanced JavaReplies: 1Last Post: 04-22-2008, 03:11 AM -
problem with ResultSet.updateRow()
By kvikas in forum New To JavaReplies: 0Last Post: 04-14-2008, 10:00 AM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks