This week's book giveaway is in the OO, Patterns, UML and Refactoring forum.
We're giving away four copies of Refactoring for Software Design Smells: Managing Technical Debt and have Girish Suryanarayana, Ganesh Samarthyam & Tushar Sharma on-line!
See this thread for details.
The moose likes JDBC and Relational Databases and the fly likes cannot retrieve table from my java program Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

JavaRanch » Java Forums » Databases » JDBC and Relational Databases
Bookmark "cannot retrieve table from my java program" Watch "cannot retrieve table from my java program" New topic

cannot retrieve table from my java program

sunil ingalagi

Joined: Apr 23, 2008
Posts: 17
Hi..beginner in java programming...
i have written java pgm to update and delete records from frame.
i have created a column called 'r_code' in 'reason_code' table in oracle database. i can access all r_code data in jComboBox but it is giving me sqlException as Error java.sql.SQLException: ORA-01722: invalid number

im getting error in following block

private void jComboBox1ActionPerformed(java.awt.event.ActionEvent evt) {
con = DriverManager.getConnection("jdbcracle:thin:@localhost:1521:MyDatas","scott","tiger");
String selected_id = (String)jComboBox1.getSelectedItem();
stmt = con.createStatement();
rs = stmt.executeQuery("SELECT tran_type,msc_type,resp,resp_desc,r_desc FROM reason_code WHERE r_code = " + selected_id);;

catch(Exception e)
System.out.println("Error " + e);

please help me to solve this problem
Jeanne Boyarsky
author & internet detective

Joined: May 26, 2003
Posts: 32481

Welcome to JavaRanch!

Is the code a number or can it have letter in it?

If the later it should be:
... WHERE r_code = '" + selected_id + "'");

[OCA 8 book] [Blog] [JavaRanch FAQ] [How To Ask Questions The Smart Way] [Book Promos]
Other Certs: SCEA Part 1, Part 2 & 3, Core Spring 3, TOGAF part 1 and part 2
sunil ingalagi

Joined: Apr 23, 2008
Posts: 17
Thank you very much Jeanne you solved my problem.............
I agree. Here's the link:
subject: cannot retrieve table from my java program
jQuery in Action, 3rd edition