标签:主键 数据库 book upd 操作 lse ... finally ted
Statement stmt = null; ResultSet rs = null; try { stmt = conn.createStatement(java.sql.ResultSet.TYPE_FORWARD_ONLY, java.sql.ResultSet.CONCUR_UPDATABLE); // ... // 省略若干行(如上例般创建demo表) // ... stmt.executeUpdate( "INSERT INTO autoIncTutorial (dataField) " + "values (‘Can I Get the Auto Increment Field?‘)", Statement.RETURN_GENERATED_KEYS); // 向驱动指明需要自动获取generatedKeys! int autoIncKeyFromApi = -1; rs = stmt.getGeneratedKeys(); // 获取自增主键! if (rs.next()) { autoIncKeyFromApi = rs.getInt(1); } else { // throw an exception from here } rs.close(); rs = null; System.out.println("Key returned from getGeneratedKeys():" + autoIncKeyFromApi); } finally { ... }
标签:主键 数据库 book upd 操作 lse ... finally ted
原文地址:https://www.cnblogs.com/wrkjwl/p/9229217.html