当前位置:Gxlcms > 数据库问题 > MYSQL 之 JDBC(五): PreparedStatement

MYSQL 之 JDBC(五): PreparedStatement

时间:2021-07-01 10:21:17 帮助过:18人阅读

void testPreparedStatement() { Connection connection = null; PreparedStatement ps = null; try { connection = JDBCTools.getConnection(); String sql = "insert into t_user (id, username, pwd, regTime, lastLoginTime) values(?,?,?,?,?)"; ps = connection.prepareStatement(sql); ps.setInt(1, 2); ps.setString(2, "狗贼"); ps.setString(3, "123456"); ps.setDate(4, new Date(System.currentTimeMillis())); ps.setTimestamp(5, new Timestamp(System.currentTimeMillis())); ps.executeUpdate(); } catch (Exception e) { e.printStackTrace(); } finally { JDBCTools.release(ps, connection); } }

 


————————————————
版权声明:本文为CSDN博主「李英俊小朋友」的原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接及本声明。
原文链接:https://blog.csdn.net/qq_21579045/article/details/105386353

MYSQL 之 JDBC(五): PreparedStatement

标签:class   article   文章   tools   并且   占位符   style   try   trace   

人气教程排行