You could use a [Pooling Data Source][1] to limit the number of opened connections. InitialContext ctx = new InitialContext(); DataSource ds =(DataSource)ctx.lookup("java:comp/env/jdbc/MySQLDB"); Connection connection = null; try { connection = ds.getConnection(); //... }finally{ try{ if(null != connection){ connection.close(); } }catch(Exception ex){ // use a more specific exception // logging } } Moreover, use [Prepared Statement][2] instead of Statements, it gives automatic prevention of SQL injection attacks. Use proper logging instead of `printStackTrace` [1]: http://dev.mysql.com/doc/connector-j/en/connector-j-usagenotes-j2ee-concepts-connection-pooling.html [2]: http://docs.oracle.com/javase/tutorial/jdbc/basics/prepared.html