【发布时间】:2013-09-03 01:59:18
【问题描述】:
在下面的代码中,我想调用一个存储过程并执行一个查询。我在statement.executeUpdate(); 遇到错误请帮助修复它。我不确定哪里出错了。
public void Dbexe() {
Connection connection;
connection = DatabaseConnection.getCon();
CallableStatement stmt;
try {
stmt = connection.prepareCall("{CALL optg.Ld_SOpp}");
stmt.executeUpdate();
stmt.close();
} catch (SQLException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
System.out.println("Stored Procedure executed");
//PreparedStatement statement = null;
// ResultSet rs = null;
try{
PreparedStatement statement;
try {
statement = connection.prepareStatement("MERGE INTO OPTG.R_VAL AS TARGET USING" +
........... +
"");
statement.executeUpdate(); //Here the exception is thrown
statement.close();
connection.commit();
connection.close();
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
// statement = connection.prepareStatement(query);
//statement.close();
}
finally{
System.out.println("Data is copied to the Table");
}
}
【问题讨论】:
-
问题似乎出在您尝试执行的 sql 语句中。我的意思是,是来自 DB2 的错误,而不是来自 java 的错误。可能我们需要整个 sql 语句来确定错误在哪里。
-
嗨,你是对的..问题出在查询中。我纠正了。谢谢你。
-
太棒了!你很高兴:)
标签: java sql stored-procedures jdbc db2