我有代码,用于定义具有驱动程序名称,主机,架构和其他详细信息的JDBC连接字符串。我想通过从属性文件中填充这些值来泛化创建此连接字符串的过程。
String url = "jdbc:oracle:thin:@//location.tcs.com:1520/ndrc.retg/com";
Properties props = new Properties();
props.setProperty("user", "scott");
props.setProperty("password", "Mylife");
但是我不知道该如何去做...请任何人帮助我。
答案 0 :(得分:1)
Properties jdbc;
String url ;
private static void loadProperties(String path)
{
Properties props = new Properties();
java.io.InputStream in = getClass().getResourceAsStream(path);
try
{
props.load(in);
}
catch(IOException e)
{
}
jdbc = props;
}
private void setProps() {
url = jdbc.getProperty("CONNECTIONSTRING")
}
public static void main (String[] args) throws Throwable {
Connection conn = DriverManager.getConnection(loadProperties(args[0]));
}