在下面的代碼中,我想調用一個存儲過程並執行一個查詢。我在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語句來確定錯誤的位置。 – dic19
嗨,你正確..問題出在查詢。我糾正了。謝謝你。 – 123HIS
太棒了!你很歡迎:) – dic19