Venu Gopal Burra

Greenhorn
+ Follow
since Nov 24, 2003
Merit badge: grant badges
For More
Cows and Likes
Cows
Total received
0
In last 30 days
0
Total given
0
Likes
Total received
0
Received in last 30 days
0
Total given
0
Given in last 30 days
0
Forums and Threads
Scavenger Hunt
expand Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt

Recent posts by Venu Gopal Burra

Hi,
Is there any way to access websphere data source using Normal Java Client.
I tried to access in this way
import javax.naming.*;
import java.sql.*;
import javax.sql.*;
import java.util.*;
public class DSTest
{
public static void main(String args[])
{
Connection con=null;
try
{
java.util.Properties p = new java.util.Properties();
p.put(Context.INITIAL_CONTEXT_FACTORY,"com.ibm.websphere.naming.WsnInitialContextFactory");

p.put(Context.PROVIDER_URL,"iiop://server ortno");
javax.naming.Context ctx = new javax.naming.InitialContext(p);

System.out.println("trying to lookup rpool jdbc datasource");
Object obj=ctx.lookup("comp:java/env/jdbc/datasourcename");
//And in this way also
//Object obj=ctx.lookup("jdbc/datasourcename");
System.out.println("This is object type-->"+obj.getClass());
//DataSource source = (javax.sql.DataSource) javax.rmi.PortableRemoteObject.narrow(obj, javax.sql.DataSource.class);
DataSource source = ( DataSource )obj;

con=source.getConnection();
Statement st=con.createStatement();
ResultSet rs=st.executeQuery("select * from emp ");
while(rs.next())
{
System.out.println("This is value"+rs.getString(1));
}
}
catch(Exception e)
{
System.out.println("Exception "+e);
e.printStackTrace();
}
finally
{
try
{
con.close();
}
catch(Exception e){}
}
}
}

When I tried to execute this program either I'm getting Name not found exception or class cast exception (i.e. at that time websphere is returning javax.naming.Reference then I'm trying to cast to Datasource)
Anybody can help me in this.
Thanks in advance.
20 years ago