Results 1 to 5 of 5
Thread: Jcombobox + jdbc
- 11-15-2010, 01:36 PM #1
Member
- Join Date
- Jul 2010
- Posts
- 32
- Rep Power
- 0
Jcombobox + jdbc
Java Code:Im trying to populate a Jcombobox with the data from a table and use that data to display related data fields into the TextFields : ---------------------------------------------------------------------- //Here i load the data into the Jcombobox it works perfect. plan_name ="select DISTINCT(plan_code),pln_bot_lvl, dim_code,PLN_MEM_TCDE,RW_MODE from usr_pln_rghts"; try { connection.statement = connection.connection.createStatement(); ResultSet r = connection.statement.executeQuery(plan_name); while(r.next()) { String plns = r.getString("plan_code"); planNameCmb.addItem(plns); } -------------------------------------------------------------------- //Here i want to get the combobox selected item and display the related data into the TextFields but it does not work i dnt knw what might be a problem . if (e.getSource()==planNameCmb) // { // planNameCmb.removeAllItems(); try { connection.statement = connection.connection.createStatement(); pln_name = "select pln_bot_lvl,RW_MODE, dim_code,PLN_MEM_TCDE, from usr_pln_rghts where plan_code = " + "'"+planNameCmb.getSelectedItem()+"'"; ResultSet rc = connection.statement.executeQuery(plan_name); while (rc.next()) { levelTxt.setText(rc.getString("pln_bot_lvl")); rightsTxt.setText(rc.getString("RW_MODE")); modeTxt.setText(rc.getString("dim_code")); memTxt.setText(rc.getString("PLN_MEM_TCDE")); } } catch (SQLException ex) { Logger.getLogger(userAccessUI.class.getName()).log(Level.SEVERE, null, ex); } }
- 11-15-2010, 05:29 PM #2
Moderator
- Join Date
- Apr 2009
- Posts
- 10,438
- Rep Power
- 16
Are you getting any exceptions thrown?
What does "does not work" mean?
As a side note, there's no point SELECTing all those rows in the first SQL statement if you're only actually using the plan_code. Waste of bandwidth.
Also for the second query, you should be using a PreparedPreparedStatement (Java Platform SE 6)Statement rather than concatenating the plan code String into the query. Not knowing what that String is, it is possible that that is your problem.
- 11-16-2010, 12:32 PM #3
Member
- Join Date
- Jul 2010
- Posts
- 32
- Rep Power
- 0
Java Code:i did try to use preparedStatement and its throwing this error " java.sql.SQLException: ORA-00936: missing expression" if (e.getSource()==planNameCmb) { try { PreparedStatement pstmt = connection.connection.prepareStatement("select pln_bot_lvl,RW_MODE, dim_code,PLN_MEM_TCDE, from usr_pln_rghts "+ " WHERE plan_code = ?"); pstmt.setString(1, (String)planNameCmb.getSelectedItem()) ; ResultSet rc = pstmt.executeQuery(); while (rc.next()) { levelTxt.setText(rc.getString("pln_bot_lvl")); rightsTxt.setText(rc.getString("RW_MODE")); modeTxt.setText(rc.getString("dim_code")); memTxt.setText(rc.getString("PLN_MEM_TCDE")); } } catch (SQLException ex) { Logger.getLogger(userAccessUI.class.getName()).log(Level.SEVERE, null, ex); } }
- 11-16-2010, 12:57 PM #4
Moderator
- Join Date
- Apr 2009
- Posts
- 10,438
- Rep Power
- 16
"select pln_bot_lvl,RW_MODE, dim_code,PLN_MEM_TCDE, from..."
You have a comma in the wrong place after PLN_MEM_TCDE.
- 11-16-2010, 01:34 PM #5
Member
- Join Date
- Jul 2010
- Posts
- 32
- Rep Power
- 0
Similar Threads
-
Activate JComboBox 1 when object is selected in JComboBox 2...
By bahumbaba in forum AWT / SwingReplies: 2Last Post: 12-10-2009, 01:58 PM -
JCombobox
By daniel50096230 in forum NetBeansReplies: 1Last Post: 09-21-2008, 12:23 PM -
JComboBox
By Fosters in forum AWT / SwingReplies: 0Last Post: 08-10-2008, 01:22 PM -
How to use JDBC Template classes to control basic JDBC processing and error handling
By Java Tip in forum Java TipReplies: 0Last Post: 04-01-2008, 10:17 AM -
How to use JDBC Template classes to control basic JDBC processing and error handling
By JavaBean in forum Java TipReplies: 0Last Post: 09-28-2007, 12:56 PM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks