Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

How to use JNDI to get connection from pool?

2 views
Skip to first unread message

Harry

unread,
Aug 23, 2002, 4:20:36 AM8/23/02
to
Using WL 5.1 & Oracle 8i (thin driver)

My connection pool i.e

weblogic.jdbc.connectionPool.hazardouswaste=\
url=jdbc:oracle:thin:@p1900:1521:p1900,\
driver=oracle.jdbc.driver.OracleDriver,\
initialCapacity=1,\
maxCapacity=1,\
capacityIncrement=1,\
props=user=tact_dev;password=tact_dev,\
allow=guest

A previous post suggested a way to get a connection from this pool
from an external program was to use JNDI -

How exactly do I do this?

In my weblogic.properties I've added these lines (don't really
understand them but got from other postings!)

weblogic.jdbc.DataSource.weblogic.jdbc.connectionPool.hazardouswaste=hazardouswaste
weblogic.jdbc.TXDataSource.hazardouswaste=hazardouswaste

From my program I'm using -

Context ctx = getInitialContext(); // This works fine
javax.sql.DataSource home = (javax.sql.DataSource)
ctx.lookup("hazardouswaste");

but keep getting these errors -

java.lang.NoClassDefFoundError:
COM/rsa/jsafe/JSAFE_InvalidUseException
at
weblogic.security.WLMessageDigest.getInstance(WLMessageDigest.java:53)
at
weblogic.security.MD5RandomBitsSource.seed(MD5RandomBitsSource.java:56)
at weblogic.rjvm.LocalRJVM.<init>(LocalRJVM.java:108)
etc.......

What am I doing wrong?

Why is everything so difficult when Java's concerned?

harry

Mitesh Patel

unread,
Oct 16, 2002, 4:51:24 PM10/16/02
to
You also need to define datasource like this in your config.xml and then look for it as
shown it the following code.

<JDBCDataSource JNDIName="examples-dataSource-demoPool"
Name="examples-dataSource-demoPool" PoolName="demoPool"
Targets="examplesServer"/>

You should do something like this:

import java.sql.*;
import java.util.*;
import javax.naming.*;
import javax.naming.Context;
import javax.transaction.NotSupportedException;
import javax.transaction.RollbackException;
import javax.transaction.Status;
import javax.transaction.Transaction;
import javax.transaction.TransactionManager;
import javax.transaction.xa.XAResource;
import javax.naming.*;
import java.rmi.*;
import javax.transaction.*;

public class simplesql extends Thread{

java.sql.Connection conn = null;
java.sql.Statement stmt = null;
java.sql.ResultSet rs =null;
java.sql.Connection conn2 = null;

public void run()
{
try {

// ============== Make connection to database ==================
// Obtain a Datasource connection from the WebLogic JNDI tree.
Context ctx = null;

// Put connection properties in to a hashtable.
Hashtable ht = new Hashtable();
ht.put(Context.INITIAL_CONTEXT_FACTORY,
"weblogic.jndi.WLInitialContextFactory");
ht.put(Context.PROVIDER_URL,
"t3://localhost:7001");

// Get a context for the JNDI look up
ctx = new InitialContext(ht);
javax.sql.DataSource ds
= (javax.sql.DataSource) ctx.lookup
("oraTxDS3");//ZeusDataSource");//oraTxDS");//

Mitesh

0 new messages