ThinkChat2.0新版上线,更智能更精彩,支持会话、画图、阅读、搜索等,送10W Token,即刻开启你的AI之旅 广告
~~~ package cy.db; import java.util.*; import java.sql.*; public class Conn { PreparedStatement ps=null; Connection ct=null; //声明Connection对象 ResultSet rs=null;//声明ResultSet类,用来存放获取的结果集!! String driver="com.mysql.jdbc.Driver"; String url="jdbc:mysql://122.14.200.136:3306/javadb"; String user="root"; String passwd="6a133f0024"; public Conn() { try { Class.forName(driver); ct=DriverManager.getConnection(url,user,passwd); } catch (Exception e) {} } public ResultSet query(String sql,String []paras) { try { ps=ct.prepareStatement(sql); for(int i=0;i<paras.length;i++) { ps.setString(i+1, paras[i]); } rs=ps.executeQuery(); } catch (Exception e) {} return rs; } public void close() { try { if(rs!=null) rs.close(); if(ps!=null) ps.close(); if(ct!=null) ct.close(); } catch (Exception e) {} } } ~~~