Reputation: 1339
I'm trying to use Mybatis to run a SQL script to initialize a database as shown here but get an SQLException
saying "not implemented by SQLite JDBC driver". I've checked that my SQL statement is valid and it works on the very same database via both the console interface and Java's PreparedStatement
.
Here's my initialization class along with the code that successfully creates the table commented out:
public void init() throws Exception {
ClassLoader loader = Thread.currentThread().getContextClassLoader();
InputStream stream = loader.getResourceAsStream("db_init.sql");
try (Connection conn = getConnection()) {
ScriptRunner sr = new ScriptRunner(conn);
sr.runScript(new InputStreamReader(stream));
//PreparedStatement stmt = conn.prepareStatement("CREATE TABLE IF NOT EXISTS TestTable (testColumn TEXT);");
//stmt.execute();
} catch (Exception e) {
throw e;
}
}
The SQL contained in db_init.sql
is exactly the same as in the commented conn.prepareStatement()
call.
And here is the console output this generates:
CREATE TABLE IF NOT EXISTS TestTable (
testColumn TEXT
)
Error executing: CREATE TABLE IF NOT EXISTS TestTable (
testColumn TEXT
)
. Cause: java.sql.SQLException: not implemented by SQLite JDBC driver
org.apache.ibatis.jdbc.RuntimeSqlException: Error executing: CREATE TABLE IF NOT EXISTS TestTable (
testColumn TEXT
)
. Cause: java.sql.SQLException: not implemented by SQLite JDBC driver
at org.apache.ibatis.jdbc.ScriptRunner.executeLineByLine(ScriptRunner.java:150)
at org.apache.ibatis.jdbc.ScriptRunner.runScript(ScriptRunner.java:110)
at fi.basse.shamery.db.Database.init(Database.java:60)
at fi.basse.shamery.Main.main(Main.java:19)
Caused by: java.sql.SQLException: not implemented by SQLite JDBC driver
at org.sqlite.jdbc3.JDBC3Statement.unused(JDBC3Statement.java:387)
at org.sqlite.jdbc3.JDBC3Statement.setEscapeProcessing(JDBC3Statement.java:382)
at org.apache.ibatis.jdbc.ScriptRunner.executeStatement(ScriptRunner.java:230)
at org.apache.ibatis.jdbc.ScriptRunner.handleLine(ScriptRunner.java:210)
at org.apache.ibatis.jdbc.ScriptRunner.executeLineByLine(ScriptRunner.java:143)
... 3 more
Is there a way to get ScriptRunner.runScript()
working or do I have to parse and execute the statements in my code?
Thank you!
Upvotes: 0
Views: 557
Reputation: 3594
It's the escape processing that is not implemented by the driver.
Disabling escape processing should work.
ScriptRunner sr = new ScriptRunner(conn);
sr.setEscapeProcessing(false);
sr.runScript(new InputStreamReader(stream));
Upvotes: 3