|
import lavasoft.common.DBToolkit; import java.sql.CallableStatement;
import java.sql.Connection;
import java.sql.SQLException;
import java.sql.Types;
/**
* JDBC调用MySQL5存储过程
*
* @author leizhimin 2009-12-4 10:33:12
*/
public> public static void main(String[] args) {
testExeProcedure();
}
public static void testExeProcedure() {
Connection conn = DBToolkit.getConnection();
//创建调用存储过程的预定义SQL语句
String sql = "{call testprocedure(?,?,?)}";
try {
//创建过程执行器
CallableStatement cstmt = conn.prepareCall(sql);
//设置入参和出参
cstmt.setString(1, "wangwu");
cstmt.setString(2, "111111");
cstmt.registerOutParameter(3, Types.BIGINT); //注册出参
cstmt.executeUpdate();
//获取输出参数值(两种方式都行)
Long>
//Long>
System.out.println("本次插入数据的id=" +> } catch (SQLException e) {
e.printStackTrace();
} finally {
DBToolkit.closeConnection(conn);
}
}
}
|
|
|