在内存DB中创建Derby SQL语法异常

时间:2013-09-17 20:42:35

标签: java oracle maven derby

我正在尝试在内存数据库中创建Derby进行测试,以镜像我们使用的Oracle数据库。我试图执行我们使用的第一个设置Oracle数据库的脚本,但是我得到了一个SQLSyntaxException。

的Maven:

<dependency>
   <groupId>org.apache.derby</groupId>
   <artifactId>derby</artifactId>
   <version>10.10.1.1</version>
</dependency>

代码:

private static String sqlStatement ="set echo on\n" + 
        "set feedback on\n" + 
        "set serveroutput on\n" + 
        "var start_date  varchar2(80);\n" + 
        "var start_date  varchar2(80);\n" + 
        "var end_date    varchar2(80);\n" + 
        "var sid         varchar2(10);\n" + 
        "var host        varchar2(30);\n" + 
        "var user        varchar2(30);\n" + 
        "spool DS_Create_Schema.log;\n" + 
        "\n" + 
        "begin\n" + 
        "  select to_char(sysdate, 'mm-dd-yyyy hh24:mi:ss') into :start_date from dual;\n"
        ...

final String sql = sqlStatement;
final String connURL = "jdbc:derby:memory:memdatabase;create=true";
Connection conn = null;
try {
    conn = DriverManager.getConnection(connURL);
    PreparedStatement ps = conn.prepareStatement(sql);

    boolean success = ps.execute();
    System.out.println("Memory database created: " + success);


} catch (SQLException e) {...

1 个答案:

答案 0 :(得分:0)

Derby不支持您的大多数Oracle SQL * PLus,您必须将其转换为更标准的SQL。