0

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!

13
  • 3
    More detail is needed here. What error are you seeing? Commented Jul 11, 2012 at 10:10
  • Please inform us about what error it is. Commented Jul 11, 2012 at 10:12
  • Sorry for not saying, the error is that the data isnt inserted to the table Commented Jul 11, 2012 at 10:12
  • 1
    You have set autoCommit to false but not done a commit? Commented Jul 11, 2012 at 10:14
  • 2
    Also it is more safe to use prepared statement (no sql injection). private static final String SQL_INSERT = "INSERT INTO 'catalogos' ('id', 'name', 'keywords') VALUES (?, ?, ?)"; Commented Jul 11, 2012 at 10:34

2 Answers 2

2

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?

Sign up to request clarification or add additional context in comments.

1 Comment

As i said i'm quite new to programming. Could you tell me what a commit is?I don't know what it is so I don't know if it is wrong
0

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

Comments