JDBC追加记录后使用API获得新追加记录的主键值 http://kin111.blog.51cto.com/738881/168499
public static int setScore() {
int result = 0;
ResultSet rs = null;
Connection conn = null;
PreparedStatement pstmt = null;
String sql = "update ";
try {
conn = DBLink.getConn();
pstmt = conn.prepareStatement(sql);
result = pstmt.executeUpdate();
rs = pstmt.getGeneratedKeys();
if (rs.next()) {
result = (new Integer(((Serializable) rs.getObject(1))
.toString()));
}
} catch (Exception e) {
e.printStackTrace();
} finally {
if (conn != null) {
try {
pstmt.close();
} catch (SQLException sx) {
sx.printStackTrace();
}
DBLink.releaseConn(conn);
}
}
return result;
}