MySQL操作类(本人自己写的)_MySQL
程序员文章站
2024-01-22 10:36:46
...
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