是否可以从Java创建新的PDB?

时间:2019-01-25 06:57:24

标签: java oracle12c

对于我其中之一,我想用Java创建一个新的PDB。

我能够说出cdb连接,

Connection cdbConnection = DBUtils.getDBConnection(Constants.DB_CDB_NAME, Constants.DB_CDB_USER_NAME, Constants.DB_CDB_PASSWORD);

现在我要克隆PDB3:CREATE PLUGGABLE DATABASE PDB5 FROM PDB3;

public static void createPluggableDB(Connection cdbConnection) {
  try (Statement stmt = cdbConnection.createStatement();) {
     stmt.executeUpdate("CREATE PLUGGABLE DATABASE PDB5 FROM PDB3;");
  } catch (SQLException exception) {
    // exception handling
  }
}

执行此命令时,我会得到

java.sql.SQLSyntaxErrorException: ORA-00922: missing or invalid option
at oracle.jdbc.driver.T4CTTIoer11.processError(T4CTTIoer11.java:494)
at oracle.jdbc.driver.T4CTTIoer11.processError(T4CTTIoer11.java:446)
at oracle.jdbc.driver.T4C8Oall.processError(T4C8Oall.java:1052)
at oracle.jdbc.driver.T4CTTIfun.receive(T4CTTIfun.java:537)
at oracle.jdbc.driver.T4CTTIfun.doRPC(T4CTTIfun.java:255)
at oracle.jdbc.driver.T4C8Oall.doOALL(T4C8Oall.java:610)
at oracle.jdbc.driver.T4CStatement.doOall8(T4CStatement.java:213)
at oracle.jdbc.driver.T4CStatement.doOall8(T4CStatement.java:37)
at oracle.jdbc.driver.T4CStatement.executeForRows(T4CStatement.java:887)
at oracle.jdbc.driver.OracleStatement.doExecuteWithTimeout(OracleStatement.java:1136)
at oracle.jdbc.driver.OracleStatement.executeInternal(OracleStatement.java:1754)
at oracle.jdbc.driver.OracleStatement.execute(OracleStatement.java:1709)
at oracle.jdbc.driver.OracleStatementWrapper.execute(OracleStatementWrapper.java:300)
at com.xit.gtw.db.DBUtils.executeDBScripts(DBUtils.java:43)
at PluggableDBBuilder.createPluggableDB(PluggableDBBuilder.java:51)
at PluggableDBBuilder.main(PluggableDBBuilder.java:35)

是否可以通过Java创建PDB?

谢谢!

1 个答案:

答案 0 :(得分:0)

传递给executeUpdate()的字符串中不应包含分号;这是一个语句分隔符,不是语句的一部分。所以删除它:

stmt.executeUpdate("CREATE PLUGGABLE DATABASE PDB5 FROM PDB3");

这适用于您尝试通过JDBC(或者实际上通过许多其他机制-包括execute immediate)执行的任何语句。