1 package com.test; 2 import java.sql.Connection; 3 import java.sql.DriverManager; 4 import java.sql.PreparedStatement; 5 import java.sql.ResultSet; 6 import java.util.Vector; 7 public class DBUtil { 8 9 //定义连接数据库需要的10 Connection ct=null;11 PreparedStatement pS=null;12 ResultSet rS=null;13 private static String url = "jdbc:mysql://"+DBSomeType.MYSQLURL+":3306/weixin?characterEncoding=UTF-8&autoReconnect=true";14 private static String driverName = "com.mysql.jdbc.Driver";15 16 /**17 * 数据库查询,本操作查询完需手动关闭连接18 * @param sql19 * @param params20 * @return 查询结果ResultSet21 */22 public ResultSet getSlect(String sql,Object ...params){23 Vector rowDate=new Vector();24 Vector columnDate =new Vector();25 try {26 ct = connectWithDB();27 pS=ct.prepareStatement(sql);28 for(int i = 0;i < params.length;i++){29 pS.setObject(i+1, params[i]);30 }31 rS=pS.executeQuery();32 } catch (Exception e) {33 // TODO: handle exception34 }finally{35 return rS;36 }37 }38 39 /************修改数据库操作*********************/40 public int update(String sql,Object ...params){41 int executeUpdate_int = 0;42 try {43 ct = connectWithDB();44 pS=ct.prepareStatement(sql);45 for(int i = 0;i < params.length;i++){46 pS.setObject(i+1, params[i]);47 }48 //执行操作49 executeUpdate_int = pS.executeUpdate();50 System.out.println("executeUpdate_int = "+executeUpdate_int);51 } catch (Exception e) {52 // TODO: handle exception53 }finally{54 shutDownDB();55 return executeUpdate_int;56 }57 }58 59 /************连接数据库*********************/60 private Connection connectWithDB(){61 Connection connection = null;62 try {63 Class.forName(driverName);64 connection= DriverManager.getConnection(url, DBSomeType.ROOTUSERNAME, DBSomeType.ROOTPASSWORD);65 } catch (Exception e) {66 // TODO: handle exception67 }68 return connection;69 }70 71 /************关闭数据库的相关连接*********************/72 public void shutDownDB(){73 try74 {75 if(rS!=null) rS.close();76 if(pS!=null) pS.close();77 if(ct!=null) ct.close();78 } catch (Exception e2)79 {80 e2.printStackTrace();81 // TODO: handle exception82 }83 }84 85 }
每个人都需要一台速度更快、更稳定的 PC。随着时间的推移,垃圾文件、旧注册表数据和不必要的后台进程会占用资源并降低性能。幸运的是,许多工具可以让 Windows 保持平稳运行。
C++高性能并发应用_C++如何开发性能关键应用
Java AI集成Deep Java Library_Java怎么集成AI模型部署
Golang后端API开发_Golang如何高效开发后端和API
Python异步并发改进_Python异步编程有哪些新改进
C++系统编程内存管理_C++系统编程怎么与Rust竞争内存安全
Java GraalVM原生镜像构建_Java怎么用GraalVM构建高效原生镜像
Python FastAPI异步API开发_Python怎么用FastAPI构建异步API
C++现代C++20/23/26特性_现代C++有哪些新标准特性如modules和coroutines
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号