Connection con = DBConnector.getconecttion(); // 取得一个数据库连接
CallableStatement cst = null;
con.setAutoCommit(false);
String insertSql = "begin insert into TABLE (field_0,field_1) values (value_0,value_1) returning id into ?;end; ";
try {
cst = con.prepareCall(insertSql); //执行存储过程
cst.registerOutParameter(1, Types.INTEGER); //为存储过程设定返回值
int count = cst.executeUpdate(); //得到预编译语句更新记录或删除操作的结果
int id = cst.getInt(1); //得到返回值
System.out.println("成功执行了:" + count + "条数据,其ID值:" + id);
} catch (SQLException e1) {
con.rollback();
con.setAutoCommit(true);
}finally{
con.commit();
con.close();
}