当前位置:Gxlcms > 数据库问题 > DBCP 数据源获取连接

DBCP 数据源获取连接

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

int M1() { int res = -1; try { Connection conn = getConnection(); String sql = "UPDATE `user` set money=666 where id=?"; Object[] objs = new Object[]{"1"}; res = JdbcUtils.executeUpdate(conn, sql, objs); System.out.println(res); } catch (Exception e) { e.printStackTrace(); } return res; } private Connection getConnection() throws SQLException { BasicDataSource bs = new BasicDataSource(); bs.setDriverClassName("com.mysql.jdbc.Driver"); bs.setUrl("jdbc:mysql://localhost:3306/jdbc"); bs.setUsername("root"); bs.setPassword("xxxxxx"); bs.setInitialSize(20); Connection connection = bs.getConnection(); return connection; }

 

DBCP 数据源获取连接

标签:span   try   mon   initial   als   private   bsp   row   object   

人气教程排行