java调用msyql函数和存储过程的方法
2009年06月25日 星期四 21:37
java调用mysql存储过程:
String procedure = "{call nextid (?)}"; // 不能写为{?= call nextid (?)}
CallableStatement cstmt = conn.prepareCall(procedure);
cstmt.setString(1, "cprounit");
cstmt.execute();
ResultSet rs = cstmt.getResultSet();
if (rs.next()) {
result = rs.getInt(1);
}
java调用myql函数的方法有两种:
1. String procedure = "{?=call test.get_next_value (?)}";
CallableStatement cstmt = conn.prepareCall(procedure);
cstmt.registerOutParameter(1, Types.INTEGER);
cstmt.setString(2, "user_id");
cstmt.execute();
result = cstmt.getInt(1);
2. String procedure = "select test.get_next_value (?)";
CallableStatement cstmt = conn.prepareCall(procedure);
cstmt.setString(1, "user_id");
cstmt.execute();
ResultSet rs = cstmt.getResultSet();
if (rs.next()) {
result = rs.getInt(1);
}
分享到:
2011-06-14 14:11
浏览 1087
评论