public void insertUser(UserInfoDTO user) throws DataAccessException {
try {
this.con = this.getConnection();
final String insertSql = "INSERT INTO USERINFO(USERID,USERName,memo) VALUES(?,?,?)";
final String selectSql = "SELECT MEMO FROM USERINFO WHERE USERID = ? FOR UPDATE";
final String updateSql = "UPDATE USERINFO SET MEME = ? WHERE USERID = ?";
PreparedStatement ps = con.prepareStatement(insertSql);
ps.setString(1, user.getUserID());
ps.setString(2, user.getUserName());
ps.setClob(3, CLOB.empty_lob());
ps.executeUpdate();
ps.close(); ps = this.con.prepareStatement(selectSql);
ps.setString(1, user.getUserID());
ResultSet rs = ps.executeQuery();
rs.next(); CLOB memo = (CLOB) rs.getClob(1);
memo.setString(1, user.getMemo()); ps = this.con.prepareStatement(updateSql);
ps.setClob(1, memo);
ps.setString(2, user.getUserID());
ps.executeUpdate();
ps.close();
this.con.commit();
} catch (Exception ex) {
throw new DataAccessResourceFailureException(ex.getMessage(), ex);
} finally {
try {
if (this.con != null)
this.con.close();
} catch (Exception ex) {
throw new DataAccessResourceFailureException(ex.getMessage(),
ex);
}
} }
try {
this.con = this.getConnection();
final String insertSql = "INSERT INTO USERINFO(USERID,USERName,memo) VALUES(?,?,?)";
final String selectSql = "SELECT MEMO FROM USERINFO WHERE USERID = ? FOR UPDATE";
final String updateSql = "UPDATE USERINFO SET MEME = ? WHERE USERID = ?";
PreparedStatement ps = con.prepareStatement(insertSql);
ps.setString(1, user.getUserID());
ps.setString(2, user.getUserName());
ps.setClob(3, CLOB.empty_lob());
ps.executeUpdate();
ps.close(); ps = this.con.prepareStatement(selectSql);
ps.setString(1, user.getUserID());
ResultSet rs = ps.executeQuery();
rs.next(); CLOB memo = (CLOB) rs.getClob(1);
memo.setString(1, user.getMemo()); ps = this.con.prepareStatement(updateSql);
ps.setClob(1, memo);
ps.setString(2, user.getUserID());
ps.executeUpdate();
ps.close();
this.con.commit();
} catch (Exception ex) {
throw new DataAccessResourceFailureException(ex.getMessage(), ex);
} finally {
try {
if (this.con != null)
this.con.close();
} catch (Exception ex) {
throw new DataAccessResourceFailureException(ex.getMessage(),
ex);
}
} }
解决方案 »
免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货