Java调用MySql数据库函数
/**
* 调用mysql的自定义函数
*
*/
private void test() {
logger.info("show task start ");
Connection conn = null;
CallableStatement cs = null;
try {
conn = Pub.getConnMysql();
//调用存储过程
conn.setAutoCommit(false);
cs = conn.prepareCall("{call " + db+ ".P_TEST()}");
cs.executeQuery();
conn.commit();
}catch (Exception e) {
logger.info("Exception: "+e.getMessage());
}finally{
try {
cs.close();
} catch (Exception ignore) {
logger.info("Exception:"+ignore.getMessage());
ignore.printStackTrace();
}
Pub.CloseConnect(conn);
}
logger.info("show task end ");
}