Database connection Tool Class
public class Dbutil {//Get input stream
private static InputStream in = DBUtil.class.getClassLoader (). getResourceAsStream ("config.properties");
private static Properties Prop = new properties ();
public static Connection getconnection () throws ClassNotFoundException, sqlexception{
try {
Prop.load (in);
catch (IOException e) {
E.printstacktrace ();
}
Connection Conn=null;
Load Driver
String driver=prop.getproperty ("Jdbc.driverclassname");//"Oracle.jdbc.OracleDriver";
Class.forName (driver);
Establish a connection
String url=prop.getproperty ("Jdbc.url");//"Jdbc:oracle:thin:@10.1.55.241:1521:test";
String username=prop.getproperty ("Jdbc.username");
String password=prop.getproperty ("Jdbc.password");
Conn=drivermanager.getconnection (Url,username,password);
Return conn;
}
}
My config.properties is placed under the SRC directory of the Web project.
Properties configuration file Contents
Jdbc.driverclassname=oracle.jdbc.driver.oracledriver
Jdbc.url=jdbc:oracle:thin:@10.1.55.241:1521:test
Jdbc.username=bomc
Jdbc.password=bomc
Jdbc.show_sql=true