欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

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") : "插入失败");
相关标签: Java SQL DB2