DBCP 数据源获取连接
111
private 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; }
温馨提示: 本文由Jm博客推荐,转载请保留链接: https://www.jmwww.net/SQL/21902.html
- 上一篇:[转帖]数据库,傻逼才用外键约束!
- 下一篇:idea 中使用dataBase插件