可控制的数据库配置。。。
我现在要发送一条请求 service/?request=changeConfiguration&user=abcd&password=123&url=127.0.0.1/xxx
来变更原有的数据库配置
代码如下:Cofig.properties
DB_DRIVER=org.postgresql.DriverDB_CONN_URL=jdbc\:postgresql\://127.0.0.1\:5432/zyzxDB_USER=zyzxDB_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); }