Volker Demel
Volker Demel

Reputation: 33

weblogic 12 / using plain jdbc connection

I have a WebApp where users log in using the database credentials and the backend runs prefab reports on a production database using the users credentials. Company policies does not allow a technical user in this special case.

Since a Datasource is tied to one user I use a plain JDBC connection

java.sql.Connection c = DriverManager.getConnection(aUrl, aUsername, aPassword);

This works but is this the preferred way to to this in an application server? Somehow this does not seem right.

Upvotes: 1

Views: 111

Answers (1)

Jorge_B
Jorge_B

Reputation: 9872

This way will make your database run out of available open connections and result sets (open cursors) as soon as the user concurrency reaches a certain threshold.

The usual way to do this would be to define a database connection pool with a certain user with the appropiate grants. This connection pool should have some config settings that feel comfortable to your DBA, and should keep its open connections in thresholds that are acceptable to your data base, so you will never get into problems in case of excessive concurrency (you should not reach a database problem with, let's say, 250 concurrent users, which is likely to happen with the method you describe in your post).

The way to achieve this would be to provide sound arguments to your database folks in order to properly review the company policies on database users, in terms of

  • robustness: the initial implementation will surely take your database down with its first hundreds of concurrent users - this is not possible but certain
  • performance: a connection pool will always outperform the initial idea because opening a new connection is a very expensive operation
  • ease of monitoring and administration: a technical user will allow your DBAs to instantly know and better take decisions (for example, tablespace sizing and the like) over the running queries coming to their database from the java application servers
  • security: actually the matter of who can order which report is a business logic problem, that should be delegated to an upper tier - once this is solved, just let the java application order its reports

Good luck with this!

Upvotes: 1

Related Questions