对Java调用MYSQL储存过程解析

在工作中积累一些常见的知识是必要的。做个存档
比如mysql函数名test(?,?,?)
public Boolean saveTest(String test1, String test2,
) throws Exception {
jdbcTemplate
.execute(new BatchExpStuMissionCallback(test1,test2));
return true;
}
//---------------------------------------------------------------
private class BatchTestCallback implements ConnectionCallback {
protected String test1;
protected String test2;
public BatchTestCallback (String test1, String test2) {
this.test1= test1;
this.test2= test2;
}

@Override
public Object doInConnection(Connection con) throws SQLException,
DataAccessException {
CallableStatement call = con.prepareCall("call test(?,?)");
call.setString(1, test1);
call.setString(2, test2);
boolean exe = call.execute();
call.close();
return exe;
}
}

猜你喜欢

转载自miak-chen.iteye.com/blog/1878729