I have a simple servlet that uses Tomcat-DBCP to fetch connections.
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
...
Connection conn = null;
try {
conn = createConnection();
....
}
public Connection createConnection() throws SQLException {
Connection conn = null;
DataSource datasource = new DataSource();
PoolProperties p = new PoolProperties();
p.setUrl("jdbc:oracle:thin:@localhost:1521:XE");
p.setDriverClassName("oracle.jdbc.OracleDriver");
p.setUsername("SYSTEM");
p.setPassword("password");
datasource.setPoolProperties(p);
try {
conn = datasource.getConnection();
} catch (SQLException e) {
e.printStackTrace();
}
return conn;
}
It needs ojdbc6.jar in tomcat's /lib folder and not in WEB-INF/lib.
- Why doesn't the web-apps own lib folder work?
- Based on a answer here, binding driver code with the common class loader causes memory leaks. If true, what is the workaround?