Accessing Oracle without EJB
sselena911 Aug 13, 2002 3:55 PMHello, all
Is it possible to access oracle database without the use of EJB? In other words, if I have JBoss, what/how do I need to configure WITHOUT deplying EJB so that I can run the following code:
import java.sql.*;
import javax.naming.*;
import javax.sql.DataSource;
import java.util .*;
public class JDBCTest
{
public JDBCTest (){
InitialContext context = null;
try {
context = new InitialContext();
System.out.println("Created Initial Context "+context);
for (Enumeration e = context.list(context.getNameInNamespace()); e.hasMoreElements (); ){
System.out.println(e.nextElement ().toString ());
}
DataSource ds = (DataSource)context.lookup("OracleDS");
System.out.println("Created DataSource "+ds);
Connection c = ds.getConnection();
System.out.println("Created Connection "+c);
String sql = "SELECT * FROM FX_TRADE";
PreparedStatement ps = c.prepareStatement(sql);
System.out.println("Created PreparedStatement "+ps);
ResultSet rs = ps.executeQuery ();
System.out.println("Executed Query "+rs);
} catch (Exception e){
e.printStackTrace ();
}
}
public static void main (String [] args ){
new JDBCTest ();
}
}
I have the following jndi.properties in the same directory as this class file:
java.naming.factory.initial=org.jnp.interfaces.NamingContextFactory
java.naming.provider.url=localhost:1099
java.naming.factory.url.pkgs=org.jboss.naming:org.jnp.interfaces
jnp.socketFactory=org.jnp.interfaces.TimedSocketFactory
As of now I am getting the following output:
Created Initial Context javax.naming.InitialContext@47858e
XAConnectionFactory: org.jboss.mq.SpyXAConnectionFactory
UserTransactionSessionFactory: org.jboss.tm.usertx.server.UserTransactionSession
FactoryImpl
RMIXAConnectionFactory: org.jboss.mq.SpyXAConnectionFactory
topic: org.jnp.interfaces.NamingContext
queue: org.jnp.interfaces.NamingContext
jmx:ELANA:rmi: org.jboss.jmx.adaptor.rmi.RMIAdaptorImpl
ConnectionFactory: org.jboss.mq.SpyConnectionFactory
RMIConnectionFactory: org.jboss.mq.SpyConnectionFactory
UserTransaction: org.jboss.tm.usertx.client.ClientUserTransaction
ejb: org.jnp.interfaces.NamingContext
invokers: org.jnp.interfaces.NamingContext
UILXAConnectionFactory: org.jboss.mq.SpyXAConnectionFactory
UILConnectionFactory: org.jboss.mq.SpyConnectionFactory
javax.naming.NameNotFoundException: OracleDS not bound
at sun.rmi.transport.StreamRemoteCall.exceptionReceivedFromServer(Stream
RemoteCall.java:245)
at sun.rmi.transport.StreamRemoteCall.executeCall(StreamRemoteCall.java:
220)
at sun.rmi.server.UnicastRef.invoke(UnicastRef.java:122)
at org.jnp.server.NamingServer_Stub.lookup(Unknown Source)
at org.jnp.interfaces.NamingContext.lookup(NamingContext.java:445)
at org.jnp.interfaces.NamingContext.lookup(NamingContext.java:429)
at javax.naming.InitialContext.lookup(InitialContext.java:350)
at JDBCTest.(JDBCTest.java:16)
at JDBCTest.main(JDBCTest.java:31)
Please, any help will be appreciated
Thank you,
Elana