• Post Reply Bookmark Topic Watch Topic
  • New Topic

Using CMP, How To Establish Connection to the Oracle Database?  RSS feed

JiaPei Jen
Ranch Hand
Posts: 1309
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

I am working on a J2EE Project on the WebLogic 6.0 platform. I use the container managed persistence (CMP) and each table in my Oracle database is an entity bean.
This is what I have been thinking:
Every time I use an entity bean, I should establish
the connection to the database. Therefore, I have
written a utility class (DBConnection.java)(see the
attached codes) with a
getConnection() method in it. And I should call this
method in the home interface, remote interface, and
implementation class of the entity bean I am using.
However, somebody told me that I should not use
the DBConnection class to do it. I should instead set
up the data source and configure the entity bean.
I am very confused. Where do I get the
instructions to do it in accordance with what
"somebody told me" if my way of doing it is wrong?
Thank you in advance. (Please see the attachment.)

package ConnectionUtil;
import javax.servlet.*;
import javax.servlet.http.*;
public class DBConnection {
private String host = "";
private String dbName = "TEAPP";
private Int port = 1521;
private Connection connection = null;
private String URL = "jdbc racle:thin:@" + host + ":" + port + ":" + dbname;
private String USER = "TIME123";
private String PWD = "TIME123";
public static Connection getConnection() throws DBConnectionFailedException {
try {
public void init( ServletConfig config )
throws ServletException
super.init( config );

try {
Class.forName( "oracle.jdbc.driver.oracleDriver" );
connection =
DriverManager.getConnection( URL, USER, PWD );
catch ( Exception e ) {
connection = null;
catch( Exception e ) {
DBConnectionFailedException except = new DBConnectionFailedException( String.valueOf( e ) );
System.out.println( "DBConnection exception: " + e );
throw( except );

return connection;
public void destroy()
try {
catch( Exception e ) {
System.err.println( "Problem closing the database" );
Don't get me started about those stupid light bulbs.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!