Reputation:
I have set up a program for an enterprise to handle their brochures(catalogo in spanish). I ask the user via Swings for the data, and then use it to generate a query and insert it into my db. Here is the code:
Class.forName(driver);
con = DriverManager.getConnection(url + db, user, pass);
con.setAutoCommit(false);
st = con.createStatement();
String sql = "INSERT INTO `catalogos` (`id`, `name`, `keywords`) VALUES(" + catNumIn.getText() + ", '" + catNameIn.getText() + "', '" + catKeyIn.getText() + "');";
st.executeUpdate(sql);
So i would like to know what my error is. Thank you!
Upvotes: 0
Views: 85
Reputation: 43159
Are you committing your transaction? You've said setAutoCommit(false)
after all. Could you try:
setAutoCommit(true);
instead of the line you currently have, or:
con.commit();
after your database update?
Upvotes: 2
Reputation: 13700
When you construct sql statement in your front end and have an error, the best approach is to print the variable and see if there is a problem with the values like single quotes,missing comma,etc
Upvotes: 0