无法脚本在java应用程序中的h2数据库中进行文件

时间:2017-07-04 13:42:07

标签: java exception h2 database-backups

当我尝试通过org.h2.tools.Script.process()备份我的数据库时,我不断遇到有线问题,其中没有提到详细信息:

    org.h2.jdbc.JdbcSQLException: Syntax error in SQL statement "SCRIPT  TO '' TEST[*].SQL "; SQL statement:
SCRIPT  TO '' test.sql [42000-194]
    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.message.DbException.getSyntaxError(DbException.java:191)
    at org.h2.command.Parser.getSyntaxError(Parser.java:532)
    at org.h2.command.Parser.prepareCommand(Parser.java:259)
    at org.h2.engine.Session.prepareLocal(Session.java:564)
    at org.h2.engine.Session.prepareCommand(Session.java:505)
    at org.h2.jdbc.JdbcConnection.prepareCommand(JdbcConnection.java:1204)
    at org.h2.jdbc.JdbcStatement.executeInternal(JdbcStatement.java:170)
    at org.h2.jdbc.JdbcStatement.execute(JdbcStatement.java:158)
    at org.h2.tools.Script.process(Script.java:139)
    at com.h2.examples.Example.generatBackup(Example.java:57)
    at com.h2.examples.Example.main(Example.java:40)

我的示例代码:

private static final String DB_DRIVER = "org.h2.Driver";
  private static final String DB_CONNECTION = "jdbc:h2:~/test";
  private static final String DB_USER = "";
  private static final String DB_PASSWORD = "";

  public static void main(String[] args) throws Exception {

    Example example = new Example();

    try {
      Connection connection = getDBConnection();

      example.generatBackup(connection, DB_USER, DB_PASSWORD, "test.sql");

    } catch (SQLException e) {
      e.printStackTrace();
    }
  }

  private void generatBackup(Connection connection,
                             String user,
                             String password,
                             String fileName) throws SQLException {
    Script.process(connection, user, password, fileName);
  }

}

环境:

Windows 10

Eclipse Neon.3发布(4.6.3)

H2 1.4.194

1 个答案:

答案 0 :(得分:0)

我使用的是h2 1.4.197,似乎您对参数顺序的使用不正确。有关流程API的使用,请查看以下API Method

进程(连接conn,String fileName,String options1,String options2)