gpt4 book ai didi

java - 无法在 java 应用程序中编写 h2 数据库中的脚本文件

转载 作者:太空宇宙 更新时间:2023-11-04 11:21:02 24 4
gpt4 key购买 nike

当我尝试通过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

最佳答案

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

进程(连接conn,字符串文件名,字符串选项1,字符串选项2)

关于java - 无法在 java 应用程序中编写 h2 数据库中的脚本文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44907622/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com