JAVA操作SQL插入小技巧
程序员文章站
2024-03-20 14:24:52
...
Connection conn = ConnectionPoolFactory.getSQLServerConnection(
ConfigKeys.CRM_DB2_URL, ConfigKeys.CRM_DB2_USER,
ConfigKeys.CRM_DB2_PASSWORD);
PreparedStatement stmt = conn
.prepareStatement("insert into Users(name,password,admin) values (? , ? ,0)
SELECT @@IDENTITY AS 'GUID' ");
stmt.setString(1, getMillsTimeString(6));
stmt.setString(2, getMillsTimeString(3));
ResultSet rs = stmt.executeQuery();
System.out.println(rs.next() ? rs.getString("GUID") : "插入失败");