| | |
JNDI/JDBC lookup problem with Sun Java Application Server 8.2
![]() |
I am new to JNDI, JTA, javax.sql though I am familiar with java.sql
I want to access a database (a Derby database) using JNDI lookup and UserTransaction (as I want to learn about Distributed DB Transactions).
I am using Sun Java Application Server(SJAS) 8.2
Database: Derby
Directory Services of : default from SJAS admin console
I have successfully created a connection pool and added the JDBC resource at the admin console of SJAS. I could successfully ping it.
But when I try to execute the following code it throws a exception
Code:
Output:
I know I messed up somewhere with the JNDI InitialContext thing, but don't know how to sort out the problem.
Please tell me where did I made a mistake? If possible please give some link to any good tutorial explaining this aspect of jndi/jdbc/jta
I want to access a database (a Derby database) using JNDI lookup and UserTransaction (as I want to learn about Distributed DB Transactions).
I am using Sun Java Application Server(SJAS) 8.2
Database: Derby
Directory Services of : default from SJAS admin console
I have successfully created a connection pool and added the JDBC resource at the admin console of SJAS. I could successfully ping it.
But when I try to execute the following code it throws a exception
Code:
java Syntax (Toggle Plain Text)
import java.sql.*; import java.util.*; import javax.sql.*; import javax.naming.*; import javax.transaction.*; public class DerbyDB_dist { public static void main(String args[]) { try { Properties prop=new Properties(); prop.put(Context.INITIAL_CONTEXT_FACTORY,"com.sun.jndi.ldap.LdapCtxFactory"); Context initialContext = new InitialContext(prop); DataSource ds = (DataSource)initialContext.lookup("jdbc/testdb1"); UserTransaction ut = (UserTransaction)initialContext.lookup("javax.transaction.UserTransaction"); ut.begin(); Connection con = ds.getConnection(); Statement stmt = con.createStatement(); ResultSet rs = stmt.executeQuery("SELECT * FROM abc"); while (rs.next()) { int x = rs.getInt(1); String s = rs.getString(2); System.out.println("["+x+"]\t["+s+"]"); } con.close(); ut.commit(); } catch(Exception e) { e.printStackTrace(); } } }
Output:
Java Syntax (Toggle Plain Text)
javax.naming.CommunicationException: localhost:389 [Root exception is java.net.ConnectException: Connection refused: connect] at com.sun.jndi.ldap.Connection.<init>(Connection.java:204) at com.sun.jndi.ldap.LdapClient.<init>(LdapClient.java:118) at com.sun.jndi.ldap.LdapClient.getInstance(LdapClient.java:1578) at com.sun.jndi.ldap.LdapCtx.connect(LdapCtx.java:2596) at com.sun.jndi.ldap.LdapCtx.<init>(LdapCtx.java:283) at com.sun.jndi.ldap.LdapCtxFactory.getInitialContext(LdapCtxFactory.java:53) at javax.naming.spi.NamingManager.getInitialContext(NamingManager.java:667) at javax.naming.InitialContext.getDefaultInitCtx(InitialContext.java:247) at javax.naming.InitialContext.init(InitialContext.java:223) at javax.naming.InitialContext.<init>(InitialContext.java:197) at DerbyDB_dist.main(DerbyDB_dist.java:16) Caused by: java.net.ConnectException: Connection refused: connect at java.net.PlainSocketImpl.socketConnect(Native Method) at java.net.PlainSocketImpl.doConnect(PlainSocketImpl.java:333) at java.net.PlainSocketImpl.connectToAddress(PlainSocketImpl.java:195) at java.net.PlainSocketImpl.connect(PlainSocketImpl.java:182) at java.net.SocksSocketImpl.connect(SocksSocketImpl.java:366) at java.net.Socket.connect(Socket.java:516) at java.net.Socket.connect(Socket.java:466) at java.net.Socket.<init>(Socket.java:366) at java.net.Socket.<init>(Socket.java:179) at com.sun.jndi.ldap.Connection.createSocket(Connection.java:346) at com.sun.jndi.ldap.Connection.<init>(Connection.java:181) ... 10 more
I know I messed up somewhere with the JNDI InitialContext thing, but don't know how to sort out the problem.
Please tell me where did I made a mistake? If possible please give some link to any good tutorial explaining this aspect of jndi/jdbc/jta
Weird port number, the default is 3700 (and probably not LDAP).
The following settings are all that's AFAIK required:
jvmarg value = "-Dorg.omg.CORBA.ORBInitialHost=${ORBhost}"
jvmarg value = "-Dorg.omg.CORBA.ORBInitialPort=${ORBport}"
(either as properties of environment settings).
The following settings are all that's AFAIK required:
jvmarg value = "-Dorg.omg.CORBA.ORBInitialHost=${ORBhost}"
jvmarg value = "-Dorg.omg.CORBA.ORBInitialPort=${ORBport}"
(either as properties of environment settings).
As people are clearly allowed to attack me but I'm not allowed to defend myself, I no longer post to this site.
![]() |
Similar Threads
- Problem playing MPEG 4 in JMF over HTTP? (Java)
- Problem upgrading RedHat to Sun Java 5 JRE (Java)
- jdbc help? (Java)
- Can any one help me with java application (Java)
- Adapting a Java Application to JSP/Servlets (Java)
- help to set up "Sun Java™ System Application Server PE 8" for web application (Java)
Other Threads in the Java Forum
- Previous Thread: Java Simple calc
- Next Thread: JFilerChooser default filefilter
| Thread Tools | Search this Thread |
911 addball addressbook android api append applet application apps array arrays automation binary bluetooth businessintelligence button card class client code collision component crashcourse css csv database eclipse ee error fractal free ftp game gis givemetehcodez graphics gui html ide image integer integration j2me japplet java javaarraylist javadoc javafx javaprojects jni jpanel julia jvm linked linux list loan machine map method methods migrate mobile netbeans objects oriented output phone physics printf problem program programming project projects radio recursion replaydirector reporting researchinmotion rotatetext scanner se server service set sms software sort sql string swing test textfield threads tree trolltech ubuntu utility windows






