Using CMP, How To Establish Connection to the Oracle Database?
JiaPei Jen
Ranch Hand
Joined: Nov 19, 2000
Posts: 1309
posted
0
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 = "192.168.50.20"; 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 );