具体代码如下:
public String executeSyncUser(String operator) throws Exception {
Connection conn = createConnection();
String flag = "1";
CallableStatement stmt = conn.prepareCall("{call syncUser(?,?)}");
// stmt.setLong(1, operator);
stmt.setFloat(1, Float.valueOf(operator));
stmt.registerOutParameter(2, Types.VARCHAR);
// stmt.setInt(2, flag);
try {
System.out.println("用同步开始时间" + System.currentTimeMillis());
log.info("用户同步开始时间" + new Date(System.currentTimeMillis()));
stmt.execute();
flag = stmt.getString(2);
conn.commit();
System.out.println("用户同步结束时间" + System.currentTimeMillis());
log.info("用户同步结束时间" + new Date(System.currentTimeMillis()));
} catch (Exception e) {
conn.rollback();
throw e;
} finally {
try {
if (stmt != null) {
stmt.close();
}
if (conn != null) {
releaseConnection(conn);
}
} catch (Exception e) {
throw e;
}
}
return flag;
}
本文介绍了一个使用Java实现的同步用户信息到数据库的方法。通过CallableStatement调用存储过程syncUser,传入操作者ID并获取返回的状态标识。该过程包括连接数据库、执行存储过程及关闭资源等步骤。
711

被折叠的 条评论
为什么被折叠?



