Hi,
I'm writing a Simple Java Application. Which will generate a Connection Pool.
public static void main (String args []) throws SQLException, NamingException
{
Context ctx = null;
try
{
Hashtable env = new Hashtable (5);
env.put (Context.INITIAL_CONTEXT_FACTORY, "com.sun.jndi.fscontext.RefFSContextFactory");
env.put (Context.PROVIDER_URL, "file:/tmp/JNDI");
ctx = new InitialContext(env);
}
catch (NamingException ne)
{
ne.printStackTrace();
}
OracleDataSource ods = null;
ods = new OracleDataSource();
ods.setUser("userName");
ods.setPassword("password");
ods.setURL("jdbc:oracle:thin:@DBSERVER:1521:ORACLE_WORLD");
ctx.bind("jdbc/sampledb", ods);
ods = (OracleDataSource)ctx.lookup("jdbc/sampledb");
Connection conn = ods.getConnection();
Statement stmt = conn.createStatement ();
ResultSet rset = stmt.executeQuery ("select USER from dual");
while (rset.next ())
{
System.out.println ("User name is " + rset.getString (1));
}
rset.close();
rset = null;
stmt.close();
stmt = null;
conn.close();
conn = null;
}
It's Working Fine. Now I want this Application to be independent of any 3rd Party ApI's like OracleDataSource, and to implement the ConnectionPoolDataSource.
So, I replaced this section:
ods = (OracleDataSource)ctx.lookup("jdbc/sampledb");
Connection conn = ods.getConnection();
of above Code with:
javax.sql.ConnectionPoolDataSource cpds = (javax.sql.ConnectionPoolDataSource) context.lookup("jdbc/sampledb");
javax.sql.PooledConnection pc = cpds.getPooledConnection();
Connection conn = pc.getConnection();
it throws Exception. So if can anyone help me!!!.
-
Java JNDI Connection Pool (2 messages)
- Posted by: Manas Sahu
- Posted on: March 23 2005 06:24 EST
Threaded Messages (2)
- Java JNDI Connection Pool by Giri Kosuru on March 23 2005 13:24 EST
- Password Encryption by Wael El-Khawass on October 30 2007 04:25 EDT
-
Java JNDI Connection Pool[ Go to top ]
- Posted by: Giri Kosuru
- Posted on: March 23 2005 13:24 EST
- in response to Manas Sahu
Hi Manas,
You bound the "OracleDataSource" object to JNDI.And once you got the same object through lookup, you are trying to typecast it to an incompatible object.
Giri. -
Password Encryption[ Go to top ]
- Posted by: Wael El-Khawass
- Posted on: October 30 2007 04:25 EDT
- in response to Manas Sahu
Hi For this exact example, I want the password to be saved in an encrypted format. What is the shortest path to have the password encrypted? Thanks