• Post Reply Bookmark Topic Watch Topic
  • New Topic

Error on inserting data from a comboBox

 
Patrick Mugabe
Ranch Hand
Posts: 132
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 132
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
What are you doing? You are supposed to be reading this tiny ad!
the new thread boost feature brings a LOT of attention to your favorite threads
https://coderanch.com/t/674455/Thread-Boost-feature
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!