ITeye博客

关于自增返回当前的id值

cainwise · 2009-03-24 21:55 · jdbc · Markdown

第一种			Class.forName("com.mysql.jdbc.Driver");
			conn=DriverManager.getConnection("jdbc:mysql://localhost:3306/testing","root","root");
			System.out.println(conn);
			stmt=conn.createStatement();
			 int row=stmt.executeUpdate ("insert into aa (name) values ('mars')",Statement.RETURN_GENERATED_KEYS);
			 rs = stmt.getGeneratedKeys ();
			 if ( rs.next() ) {
			    int key = rs.getInt(row);
			    System.out.println(key);
			 }

 第二种

String sql1 = "select LAST_INSERT_ID() as lastid";

评论(0)

暂无评论。

评论功能维护中,当前仅展示历史评论。