This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
The moose likes JDBC and the fly likes Error on inserting data from a comboBox Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Databases » JDBC
Bookmark "Error on inserting data from a comboBox" Watch "Error on inserting data from a comboBox" New topic
Author

Error on inserting data from a comboBox

Patrick Mugabe
Ranch Hand

Joined: Jan 08, 2002
Posts: 132
Hi, ranchers!!!
I would like to insert selected data from a comboBox into my database.
I have tried using:
String insertData = "Insert into Test " +
"Values(?, ?)";
PreparedStatement ps = con.prepareStatement(insert data);
int i =0;
ps.setString(++i, txtFullName.getText());
ps.setString(++i, (String)comboDeptID.getText());
ps.executeUpdate();
However, this is not working out and the error I am getting is that "String will be truncated". How can I get over this, Is there any better way of getting through this.
Also, what approach should I use if I am to select data from a ListBox.
Patrick Mugabe
Ranch Hand

Joined: Jan 08, 2002
Posts: 132
Not to worry, I figured out my mistake. I had allocated a small variable size for the column that takes the selected value of the comboBox. My code is OK then.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Error on inserting data from a comboBox
 
Similar Threads
SQL error:java.sql.SQLException: ORA-01008: not all variables bound
Using JDBC how to put single quotes(')
Java Code does not recognize my sequence name
Prepared Statement problem in my servlet's data manager
Inserting date into an MS Access DB