0

The code after the statement is not executed, but why? Does the statement do a return?

conn.createStatement().execute("CREATE TABLE IF NOT EXISTS WEBSITES(ID INT auto_increment, NAME VARCHAR)");
conn.createStatement().execute("INSERT INTO WEBSITES(NAME) VALUES('"+website+"')");
System.out.println(parts[0]);
  • Probably because one kind of exception is thrown and you're ignoring it. Consider providing a runnable example that demonstrates your problem – MadProgrammer May 27 '14 at 21:22
  • Assuming you have auto-commit enabled, you probably need to call `executeUpdate`. – Elliott Frisch May 27 '14 at 21:22
  • executeUpdate was the right solution =) or should I disable autocommit but I think then I have to change my code? please post your comment as answer if possible linking to the documentation (why is there the difference between execute and executeUpdate and what is it?) so I know some details. –  May 27 '14 at 21:37

1 Answers1

0

You need to use executeUpdate(),

Executes the given SQL statement, which may be an INSERT, UPDATE, or DELETE statement or an SQL statement that returns nothing, such as an SQL DDL statement.

It may also be a performance "feature" in H2.

Elliott Frisch
  • 198,278
  • 20
  • 158
  • 249