• Post Reply Bookmark Topic Watch Topic
  • New Topic

DataSource

 
Zkr Ryz
Ranch Hand
Posts: 187
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This is an "other J2EE technologies question"
How can I use a javax.sql.DataSource in a java application with out using a J2EE container?
Nowadays I have a number of java aplications that use direct connection ( acquired by Class.forName() and DriverManager.getConnection() )
And I would like to replece it's usage with DataSource from my JDBC vendor ( say Oracle ) to allow the application reuse an existing connection and avoid memory leaks in these applications.
Is there a way I can do this ?
 
Pradeep bhatt
Ranch Hand
Posts: 8933
Firefox Browser Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I think Oracle driver provides an implementation of DataSource as OracleDataSource.
http://otn.oracle.com/software/tech/java/sqlj_jdbc/index.html
[ November 18, 2003: Message edited by: Pradeep Bhat ]
 
Zkr Ryz
Ranch Hand
Posts: 187
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Pradeep Bhat:
I think Oracle driver provides an implementation of DataSource as OracleDataSource.
http://otn.oracle.com/software/tech/java/sqlj_jdbc/index.html
[ November 18, 2003: Message edited by: Pradeep Bhat ]

Exactly, as a matter of fact the whole driver has a class implementing all the interfaces, like oracle.jdbc.driver.OracleDriver implementing java.sql.Driver, OracleConnection etc.
Do you know if using and creating an instance of OracleDataSouce would be enough ? like

Have you done this before?
Am I ni th right way ?
 
Zkr Ryz
Ranch Hand
Posts: 187
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Im going to refactor my question.
Is creating and using and destroying a java.sql.Connection using the Class.forName() method istead of using a javax.sql.DataSource an exaple of Antipattern ?
 
Bill Dudney
Author
Ranch Hand
Posts: 234
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Zkr,
I'd say that using the class name is an antipattern. You don't want to be hard-coded like that because it makes your application brittle.
Most servlet containers and all J2EE app servers provide a means to specify a connection pool. Here is an example of the configuration for Roller. These 'Resource' and 'ResourceParams' elements set up a DataSource called 'jdbc/rollerdb'.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!