Where to write database info in weblogic 6.0
2 posts in topic
Flat View  Flat View

Posted By:   A_JP
Posted On:   Wednesday, December 12, 2001 07:39 PM

Hi !
I want to write a small application which uses a API (Java class, not JSP or servlet) for database connectivity. A JSP file acts as the client for the API. Since Iam new to weblogic 6.0, I don't know where to write the database info(like driver name, URL, username, pwd etc.,) and how to get those info from the Java API. Could anyone explain me about the process. Also, is there any website for the solution.


Re: Where to write database info in weblogic 6.0

Posted By:   Muhammad_Shakeel  
Posted On:   Thursday, December 13, 2001 03:20 AM


Its a bit complicated...you'll have to create JDBC Connection Pool & Data Source in weblogic using weblogic's server console (http://:7001(or whatever port you specified during installation)/console).

Now in console's left pane, click on JDBC->Connection Pools & create new connection pool there (You'll have to have appropriate drivers in weblogic's CLASSPATH for the DB you are using), then create a Data Source in JDBC->Data Sources. Thats it with console..
(you can consult Weblogic docs. for further help in creating Connection Pools & Data Sources)

Now in your code you'll have to do following :

import javax.sql.*;
import java.rmi.*;
import javax.naming.*;

Properties p = new Properties(); //will be used to hold context properties
p.put(Context.INITIAL_CONTEXT_FACTORY,"weblogic.jndi.WLInitialContextFactory"); //weblogic's initial context
p.put(Context.PROVIDER_URL,"t3://:"); //URL of the server providing the context
Context ctx = new InitialContext(p); //creating the context object with specified properties
DataSource dsn = (javax.sql.DataSource) ctx.lookup("MyDataSource"); //MyDataSource is the name of your Data Source created using Weblogic Server Console
Connection con = dsn.getConnection(); //creating a connection through that DataSource

this will give you the connection to the DataBase. you can do further DataBase tasks from here as normal...


Muhammad Shakeel

Re: Where to write database info in weblogic 6.0

Posted By:   Andrew_Phillips  
Posted On:   Wednesday, December 12, 2001 11:02 PM

I'm not sure if I understand your question but what you could do is create a java bean with your all your JDBC connection code and then use the in your jsp code to instantiate the bean which will create your connection. I have attached some URL's to bea's site. I'm not sure if I'm helping but this is a suggestion.

About | Sitemap | Contact