[jsp]代码库/**
*
* 这是插入一条数据的同时,获取该数据的则增长列的值(该例子的自增长列是id)
*
* @author LZL
*
*/
public class Auto_Increment {
private static Connection conn = null;
private static PreparedStatement pstsm = null;
private static ResultSet rs = null;
@Test
public void testGetAutoIncrement() {
try {
// 1:创建连接
conn = Jdbcutil.getConnection();
// 2:设置sql预编译语句
String sql = "INSERT INTO person (NAME,sex,age) VALUES (?,?,?);";
// 3:执行sql预编译语句(同时在参数中指定自增列)
pstsm = conn.prepareStatement(sql,
PreparedStatement.RETURN_GENERATED_KEYS);
// 4:设置参数值
pstsm.setString(1, "王五");
pstsm.setString(2, "男");
pstsm.setInt(3, 22);
// 5:发送参数,执行sql
pst