日期:2014-05-20 浏览次数:20820 次
DB_DRIVER=org.postgresql.Driver DB_CONN_URL=jdbc\:postgresql\://127.0.0.1\:5432/zyzx DB_USER=zyzx DB_PASSWORD=zyzx
public static String DRIVER; public static String URL; public static String USER; static{ FileInputStream in = null; try{ String propertyPath = System.getProperty("user.dir").concat(File.separator).concat("Config.properties"); in = new FileInputStream(propertyPath); Properties p = new Properties(); p.load(in); DRIVER = p.getProperty("DB_DRIVER"); URL = p.getProperty("DB_CONN_URL"); USER = p.getProperty("DB_USER"); DBUtil.startPool(); }catch(){}....
private static BasicDataSource ds = null; public static void startPool() { ds = new BasicDataSource(); ds.setDriverClassName((String) Configuration.DRIVER); ds.setUsername((String) Configuration.USER); ds.setPassword((String) Configuration.PASSWORD); ds.setUrl((String) Configuration.URL); } public static Connection getConnection() throws SQLException{ return ds.getConnection(); }
public void a() throws FileNotFoundException, IOException{ String path = "/config.properties"; Properties p = new Properties(); p.setProperty("DB_DRIVER", ""); p.setProperty("DB_CONN_URL", ""); p.setProperty("DB_USER", ""); p.setProperty("DB_PASSWORD", ""); p.store(new FileOutputStream(path), null); }