赞
踩
package com; import java.io.FileInputStream; import java.sql.*; import java.util.Properties; //1.获取连接对象 2.关闭连接对象---取代单元测试中的 @Before 和 @After public class JdbcUtil { private static Properties p; static { //1.读取jdbc.properties文件 try{ FileInputStream is = new FileInputStream("D:\\java0104\\jdbc--day05\\src\\jdbc.properties"); p = new Properties(); p.load(is); }catch (Exception e){ e.printStackTrace(); } } //1.获取连接对象 public static Connection getCon(){ try{ return DriverManager.getConnection(p.getProperty("url"),p); }catch (Exception e){ e.printStackTrace(); } return null; } //2.释放资源 public static void close(ResultSet rs, Statement state,Connection con){ if (rs!=null){ try { rs.close(); } catch (SQLException e) { e.printStackTrace(); } } if (state!=null){ try { state.close(); } catch (SQLException e) { e.printStackTrace(); } } if (con!=null){ try { con.close(); } catch (SQLException e) { e.printStackTrace(); } } } public static void main(String[] args) { System.out.println(getCon()); } }
package lei; import java.sql.Date; public class Emp { private int id; private String name; private String gender; private double salary; private Date join_date; private int dept_id; public Emp() { } @Override public String toString() { return "Emp{" + "id=" + id + ", name='" + name + '\'' +
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。