0

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!

1 Answer 1

3

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));
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.