0

我正在开发使用 java 开发的 Web 应用程序项目。在我的工作项目中,我需要在用户注册后动态创建数据库。我已经完成了这种方法。

但是,现在我想调用另一个模式(主数据库)中可用的一个存储过程。存储过程包含表。现在,我想在动态创建的数据库中调用该过程。

我已经编写了如下代码,任何人都可以帮助我知道这段代码有什么问题,

Connection c1 = DriverManager.getConnection(URL, USER, PASSWORD);
java.sql.CallableStatement cstmt=null;
System.out.println("Invoking the stored procedure from subscription DB........");      
String callSP="{call masterdb.createCorporateDBProc()};";
cstmt= c1.prepareCall(callSP);
cstmt.execute();

java.sql.CallableStatement cstmt=null;
try {
    System.out.println("Invoking the stored procedure from subscription DB........");      
    String callSP="{call subscription.createCorporateDBProc()}";
    cstmt = c1.prepareCall(callSP);
    int r = cstmt.executeUpdate();
    System.out.println("SP created"+r);
    System.out.println("SP invoked and executed successfully in corporate DB....");
}  catch(com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException e){
    e.printStackTrace();
    cstmt.close();
    c1.close();
}
4

1 回答 1

0

有关声明,请参见 javadoc:

http://docs.oracle.com/javase/7/docs/api/java/sql/Statement.html#executeUpdate%28java.lang.String%29

返回:(1) SQL 数据操作语言 (DML) 语句的行数或 (2) 0 用于不返回任何内容的 SQL 语句

这意味着执行过程将返回 0。如果调用成功,还要检查您的数据库。

于 2014-01-23T20:02:10.803 回答