jar包已导入packageTest;importjava.sql.Connection;importjava.sql.DriverManager;importjava.sql.ResultSet;importjava.sql.SQLException;importjava.sql.Statement;publicclassDBC...
jar包已导入
package Test;import java.sql.Connection; import java.sql.DriverManager; import java.sql.ResultSet; import java.sql.SQLException; import java.sql.Statement;public class DBConfigure {private Statement stmt = null; private ResultSet rs = null; private Connection conn = null; String sql; String strurl;/*缺省的构造函数 */ public DBConfigure() { }/*连接数据库 */ public void OpenConn() { try { // 驱动的名称 Class.forName("com.mysql.jdbc.Driver"); String user = "root"; String passwd = "123456"; String strDBname = "jobsearch"; conn = DriverManager .getConnection("jdbc:mysql://localhost/"+strDBname+"?user=" + user + "&password=" + passwd + "");// 访问的数据库的帐号密码 } catch (Exception e) { System.out.println("OpenConnection:" + e.getMessage()); } }
public ResultSet executeQuery(String sql) { stmt = null; rs = null; try { stmt = conn.createStatement(); rs = stmt.executeQuery(sql); } catch (SQLException e) { System.err.println("executeQuery:" + e.getMessage()); } return rs; }public void executeUpdate(String sql) { stmt = null; try { stmt = conn.createStatement(); stmt.executeUpdate(sql); } catch (SQLException e) { System.out.println("executeUpdate:" + e.getMessage()); } }public void closeStmt() { try { stmt.close(); } catch (SQLException e) { System.err.println("closeStmt:" + e.getMessage()); } }public void closeConn() { try { conn.close(); } catch (SQLException ex) { System.err.println("aq.closeConn:" + ex.getMessage()); } } }
输出结果为什么报错两个类都是一样的错误
展开