用java调用PL/SQL过程
我尝试从Java调用PL/SQL过程。这段代码用于从DB中选择/插入值,但当我尝试使用此查询时,它只是加载而没有完成。我在SQLDeveloper中测试了这个命令,它可以正常工作用java调用PL/SQL过程,java,sql,spring,spring-mvc,jdbc,Java,Sql,Spring,Spring Mvc,Jdbc,我尝试从Java调用PL/SQL过程。这段代码用于从DB中选择/插入值,但当我尝试使用此查询时,它只是加载而没有完成。我在SQLDeveloper中测试了这个命令,它可以正常工作 @Override public void save(Transactions transactions) { CallableStatement callStmt = null; String query = "{CALL CON_API_PKG.createTransaction(?,?,?)}"
@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();
}
}
}
使用callable语句并使用括号,如下所示
CallableStatement callStmt = null;
String query = "{call CON_API_PKG.createTransaction(?,?,?)}";
callStmt = conn.prepareCall(query);
callStmt.setLong(1, 1000);
callStmt.setLong(2, "mkyong");
if(transactions.getNote().length() > 0){
callStmt.setLong(3, "system");
}else{
callStmt.setString(3, null);
}
callStmt.executeUpdate();
没有错误?如果你让它继续运行,你会得到一些异常时间还是什么?没有任何错误,它只是无休止地运行。我现在正在更新代码,但它是一样的。我尝试过,但它和以前一样。你使用花括号{}了吗?是的,我尝试过带括号和不带括号。