weixin_慕仙1176837
2020-07-08 17:50
public void userInfo2(int i,int b){ //加载数据库驱动程序 try { Class.forName("com.mysql.jdbc.Driver"); } catch (ClassNotFoundException e) { e.printStackTrace(); } String dburl = "jdbc:mysql://47.99.75.226:3306/Database?&useSSL=false&serverTimezone=UTC&useUnicode=true&characterEncoding=utf8"; String sql = "Update UserInfo SET OnLneDay=? WHERE UserId=?"; Connection conn = null; try { conn = DriverManager.getConnection(dburl, "root", "Ccj.123456"); Statement stmt = conn.createStatement(); boolean rst = stmt.execute(sql); while (rst) { System.out.print("添加成功"); break; } } catch (SQLException e) { e.printStackTrace(); } finally { try { conn.close(); } catch (SQLException e) { e.printStackTrace(); } }
你这关闭怎么只关闭了conn,必须先关闭rst和stmt,最后再关闭conn,需要释放资源的,不然容易内存溢出
Java入门第二季 升级版
530646 学习 · 6091 问题
相似问题