Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

JPanel and JTextFields

Status
Not open for further replies.

welshspoon

Technical User
Dec 14, 2002
34
GB
Hiya

I have a JPanel which adds a new JPanel to it when an item is selected from a JList.

The updated panels display data from an SQL table but this data can change as the user is able to select other records from a combo box which then update the relevant text fields. However, fields that you need to scroll down for do not update and i cant work out why?

For example i get the data from the combo which then gets the data from the table and then update the fields. Below is an example of how i do that.
Code:
    public void getQuestion4Details() {
        try {
            stmt5 = con.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE,
            ResultSet.CONCUR_UPDATABLE );
            String Query5 = "SELECT * FROM QuestionBank WHERE QuestionID = ?";
            QueryStmt5 = con.prepareStatement(Query5);
            QueryStmt5.setString(1,Question4);
            rs5 = QueryStmt5.executeQuery();
            String test3 = QueryStmt5.toString();
            while (rs5.next()) {
                String Q4 = rs5.getString(3);
                String Q4A = rs5.getString(4);
                String Q4B = rs5.getString(5);
                String Q4C = rs5.getString(6);
                String Q4D = rs5.getString(7);
                QuestionFourLabelBox.setText(Q4);
                QuestionFourABox.setText(Q4A);
                QuestionFourBBox.setText(Q4B);
                QuestionFourCBox.setText(Q4C);
                QuestionFourDBox.setText(Q4D);
                pPane.validate();
                pPane.repaint();
            }
        } // end try
                catch (java.lang.Exception ex) {
		            ex.printStackTrace();
		        }

    }

Thanks in advance for any help
 
I've no idea in regards to your Swing question, but I do notice several things :

1) Variable names in Java should, by of thumb, begin with a lowercase letter. Uppercase words a re reserved for object types generally.

2) Why request a scrollable, and updateable ResultSet when you do not use such features - its just overhead you don't need.

3) You appear to be using a global Connection object. Potentially open to programmer error (closing in one method and re-using in another, forgetting to close etc)

4) You are not closing the ResultSet object, nor the PreparedStatement object in that code - if you are not doing it elsewhere, then you've got a large resource leak there.

5) Try to only wrap try/catch blocks in what you really need to - using them for non-relevant code just causes code to run slower.


--------------------------------------------------
Free Java/J2EE Database Connection Pooling Software
 
thanks for your reply.

basically in a nutshell my problem is if i select a record from the combobox the fields are updated, but if i scroll down to view the rest of the fields no data appears.

thanks again
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top