将jdbc连接移动到JSP中的属性文件

时间:2016-10-21 21:07:02

标签: java jsp jdbc

我对JSP和JDBC有点新手,我想知道如何将如下所示的JDBC连接移动到属性文件,例如test.properties

Class.forName("oracle.jdbc.driver.OracleDriver"); 
//Connection  conn = DriverManager.getConnection("jdbc:oracle:thin:@nyvm0467.ptc.un.org:1521:EIDMSUAT", "DBO_EIDMSUAT", "NewPassDBO_EIDMSUAT");
Connection  conn = DriverManager.getConnection("jdbc:", "ROD", "DMSP");                     
Statement statement = conn.createStatement( ResultSet.TYPE_SCROLL_INSENSITIVE,ResultSet.CONCUR_READ_ONLY );  
String queryString = "select area from helparea order by area";
ResultSet rs = statement.executeQuery(queryString);  

1 个答案:

答案 0 :(得分:0)

其中一种可能性如下。如果我错了,请纠正我

ResourceBundle resource = ResourceBundle.getBundle("C:\\Users\\S.Mandava\\workspace2\\Contactus\\src\\OIMConnection");
String name=resource.getString("dbname");
String surname=resource.getString("dbpassword"); 

Class.forName("oracle.jdbc.driver.OracleDriver"); 

Connection  conn2 = DriverManager.getConnection("jdbc:oracle:thin:@eidms-db-003.un.org:1521:EIDPMDM", resource.getString("dbname"), resource.getString("dbpassword"));
Statement statement2 = conn2.createStatement( ResultSet.TYPE_SCROLL_INSENSITIVE,ResultSet.CONCUR_READ_ONLY );  
String queryString2 = "select area from helparea order by area";
ResultSet rs2 = statement2.executeQuery(queryString2);