Connections in web application

Asked

Viewed 87 times

1

I am creating a J2EE, jsf project. They have multiple Beans and controller, and the Beans access the Database. I’m having doubts how to manage the Connection for the database, right now I only have a Connection, but it doesn’t make sense. I thought about a pool that is launched for each thread (each client) but I don’t know how to manage this pool. Some hint how to manage the Connection in a web application ?

What’s done now is every query I need to do the comic:

connection.openDBConnection();
ps = conn.getConnection( ).prepareStatement( Constants.updateValue );
....
connection.closeDBConnection();

I don’t like the idea of creating a query link or a set of queries. Thank you

  • show your code for a better analysis

  • edited commentary

  • 1

    The most common thing in Java EE is to leave the connection management to the application server, letting the container inject the context of access to the database (or even get it programmatically) instead of explicitly creating, opening and closing the connection. You can write all the code to do this management, but doing it safely and with performance takes work and requires a lot of knowledge. This article looks like a good start (I couldn’t find anything in English): http://www.codejava.net/servers/tomcat/configuring-jndi-datasource-for-database-connection-pooling-in-tomcat. And use Java 7 or 8, not 2!

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.