Skip to content

Instantly share code, notes, and snippets.

@Tiim
Last active September 2, 2015 18:45
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Tiim/78b3737d1ffeb8a65c05 to your computer and use it in GitHub Desktop.
Save Tiim/78b3737d1ffeb8a65c05 to your computer and use it in GitHub Desktop.
Exception in thread "main" org.springframework.jdbc.BadSqlGrammarException: StatementCallback; bad SQL grammar [CREATE TABLE test (id INTEGER PRIMARY KEY)]; nested exception is org.h2.jdbc.JdbcSQLException: Tabelle "TEST" besteht bereits
Table "TEST" already exists; SQL statement:
CREATE TABLE test (id INTEGER PRIMARY KEY) [42101-188]
at org.springframework.jdbc.support.SQLErrorCodeSQLExceptionTranslator.doTranslate(SQLErrorCodeSQLExceptionTranslator.java:231)
at org.springframework.jdbc.support.AbstractFallbackSQLExceptionTranslator.translate(AbstractFallbackSQLExceptionTranslator.java:73)
at org.springframework.jdbc.core.JdbcTemplate.execute(JdbcTemplate.java:415)
at org.springframework.jdbc.core.JdbcTemplate.execute(JdbcTemplate.java:439)
at TestMain.main(TestMain.java:19)
Caused by: org.h2.jdbc.JdbcSQLException: Tabelle "TEST" besteht bereits
Table "TEST" already exists; SQL statement:
CREATE TABLE test (id INTEGER PRIMARY KEY) [42101-188]
at org.h2.message.DbException.getJdbcSQLException(DbException.java:345)
at org.h2.message.DbException.get(DbException.java:179)
at org.h2.message.DbException.get(DbException.java:155)
at org.h2.command.ddl.CreateTable.update(CreateTable.java:115)
at org.h2.command.CommandContainer.update(CommandContainer.java:78)
at org.h2.command.Command.executeUpdate(Command.java:254)
at org.h2.jdbc.JdbcStatement.executeInternal(JdbcStatement.java:184)
at org.h2.jdbc.JdbcStatement.execute(JdbcStatement.java:158)
at org.springframework.jdbc.core.JdbcTemplate$1ExecuteStatementCallback.doInStatement(JdbcTemplate.java:431)
at org.springframework.jdbc.core.JdbcTemplate.execute(JdbcTemplate.java:404)
... 7 more
import org.h2.jdbcx.JdbcDataSource;
import org.springframework.jdbc.core.JdbcTemplate;
import java.io.IOException;
import java.sql.SQLException;
public class TestMain {
public static void main(String[] args) throws SQLException, IOException {
//Works:
String file = "./testdb";
//Does not work:
//String file = "mem:";
JdbcDataSource dataSource = new JdbcDataSource();
dataSource.setUrl("jdbc:h2:" + file);
JdbcTemplate temp = new JdbcTemplate(dataSource);
temp.execute("CREATE TABLE test (id INTEGER PRIMARY KEY)");
temp.update("INSERT INTO test (id) VALUES (1), (2)");
temp.query("SELECT * FROM test", (rs, rowNum) -> {
System.out.println(rs);
return null;
});
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment