【发布时间】:2018-09-10 12:59:24
【问题描述】:
我尝试从 Java 调用 PL/SQL 过程。此代码用于从 DB 中选择/插入值,但是当我尝试使用此查询时,它只是加载而没有完成。我在 SQL Developer 中测试了这个命令,它可以工作。
@Override
public void save(Transactions transactions)
{
CallableStatement callStmt = null;
String query = "{CALL CON_API_PKG.createTransaction(?,?,?)}";
Connection con = null;
//PreparedStatement ps = null;
try{
setDataSource();
con = dataSource.getConnection();
callStmt = con.prepareCall(query);
callStmt.setLong(1,transactions.getProductId());
callStmt.setLong(2, transactions.getReporterId());
if(transactions.getNote().length() > 0){
callStmt.setString(3, transactions.getNote());
}else{
callStmt.setString(3, null);
}
callStmt.executeUpdate();
/* ps = con.prepareStatement(query);
ps.setLong(1, transactions.getProductId());
ps.setLong(2,transactions.getReporterId());
if(transactions.getNote().length() > 0)
{
ps.setString(3, transactions.getNote());
}
else ps.setString(3, null);
int out = ps.executeUpdate();
*/ int out = callStmt.executeUpdate();
if(out !=0){
System.out.println("Transaction saved for product_id="+transactions.getProductId());
}else System.out.println("Transaction save failed for product_id="+transactions.getProductId());
}catch(SQLException e){
e.printStackTrace();
}finally{
try {
callStmt.close();
// ps.close();
con.close();
} catch (SQLException e) {
e.printStackTrace();
}
}
}
【问题讨论】:
-
没有错误?如果你让它继续下去,你会得到一些例外时间吗?
-
没有任何错误,它只是运行没有结束。我现在正在更新代码,但它是一样的。
标签: java sql spring spring-mvc jdbc