
public?void?userInfo2(int?i,int?b){
????//加載數(shù)據(jù)庫(kù)驅(qū)動(dòng)程序
????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();
????????}
????}

2020-11-25
你這關(guān)閉怎么只關(guān)閉了conn,必須先關(guān)閉rst和stmt,最后再關(guān)閉conn,需要釋放資源的,不然容易內(nèi)存溢出