测试类
package com.yeyue.lesson05; import com.yeyue.lesson05.utils.JdbcUtils_DBCP; import java.sql.Connection; import java.sql.PreparedStatement; import java.sql.ResultSet; import java.sql.SQLException; import java.util.Date; public class TestDBCP { public static void main(String[] args) { Connection conn = null; PreparedStatement st = null; ResultSet rs = null; try { conn = JdbcUtils_DBCP.getConnection(); //INSERT INTO `users` (id,NAME,PASSWORD,email) VALUES (6,\'wewwqw\',\'2323\',\'323wwqd\') String sql = "INSERT INTO `users` (id,NAME,PASSWORD,email,birthday) VALUES (?,?,?,?,?)"; st = conn.prepareStatement(sql); //预编译sql 不执行 st.setInt(1,6); st.setString(2,"wewwqw"); st.setString(3,"2323"); st.setString(4,"323wwqd"); //java.sql.Date 数据库 java.util.Date java new Date().getTime() 获取时间戳 st.setDate(5,new java.sql.Date(new Date().getTime())); int i = st.executeUpdate(); if(i>0){ System.out.println("插入成功"); } } catch (SQLException throwables) { throwables.printStackTrace(); }finally { JdbcUtils_DBCP.release(conn,st,rs); } } }mysql之数据连接池 (2)
内容版权声明:除非注明,否则皆为本站原创文章。