944,134 Members | Top Members by Rank

Ad:
  • Java Discussion Thread
  • Unsolved
  • Views: 7856
  • Java RSS
Mar 22nd, 2007
0

JNDI/JDBC lookup problem with Sun Java Application Server 8.2

Expand Post »
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:
java Syntax (Toggle Plain Text)
  1. import java.sql.*;
  2. import java.util.*;
  3. import javax.sql.*;
  4. import javax.naming.*;
  5. import javax.transaction.*;
  6.  
  7. public class DerbyDB_dist
  8. {
  9. public static void main(String args[])
  10. {
  11.  
  12. try
  13. {
  14. Properties prop=new Properties();
  15. prop.put(Context.INITIAL_CONTEXT_FACTORY,"com.sun.jndi.ldap.LdapCtxFactory");
  16. Context initialContext = new InitialContext(prop);
  17.  
  18. DataSource ds = (DataSource)initialContext.lookup("jdbc/testdb1");
  19. UserTransaction ut = (UserTransaction)initialContext.lookup("javax.transaction.UserTransaction");
  20. ut.begin();
  21.  
  22.  
  23. Connection con = ds.getConnection();
  24. Statement stmt = con.createStatement();
  25.  
  26. ResultSet rs = stmt.executeQuery("SELECT * FROM abc");
  27. while (rs.next())
  28. {
  29. int x = rs.getInt(1);
  30. String s = rs.getString(2);
  31. System.out.println("["+x+"]\t["+s+"]");
  32. }
  33. con.close();
  34.  
  35.  
  36. ut.commit();
  37.  
  38. }
  39. catch(Exception e)
  40. {
  41. e.printStackTrace();
  42. }
  43.  
  44. }
  45. }

Output:
Java Syntax (Toggle Plain Text)
  1. javax.naming.CommunicationException: localhost:389 [Root exception is java.net.ConnectException: Connection refused: connect]
  2. at com.sun.jndi.ldap.Connection.<init>(Connection.java:204)
  3. at com.sun.jndi.ldap.LdapClient.<init>(LdapClient.java:118)
  4. at com.sun.jndi.ldap.LdapClient.getInstance(LdapClient.java:1578)
  5. at com.sun.jndi.ldap.LdapCtx.connect(LdapCtx.java:2596)
  6. at com.sun.jndi.ldap.LdapCtx.<init>(LdapCtx.java:283)
  7. at com.sun.jndi.ldap.LdapCtxFactory.getInitialContext(LdapCtxFactory.java:53)
  8. at javax.naming.spi.NamingManager.getInitialContext(NamingManager.java:667)
  9. at javax.naming.InitialContext.getDefaultInitCtx(InitialContext.java:247)
  10. at javax.naming.InitialContext.init(InitialContext.java:223)
  11. at javax.naming.InitialContext.<init>(InitialContext.java:197)
  12. at DerbyDB_dist.main(DerbyDB_dist.java:16)
  13. Caused by: java.net.ConnectException: Connection refused: connect
  14. at java.net.PlainSocketImpl.socketConnect(Native Method)
  15. at java.net.PlainSocketImpl.doConnect(PlainSocketImpl.java:333)
  16. at java.net.PlainSocketImpl.connectToAddress(PlainSocketImpl.java:195)
  17. at java.net.PlainSocketImpl.connect(PlainSocketImpl.java:182)
  18. at java.net.SocksSocketImpl.connect(SocksSocketImpl.java:366)
  19. at java.net.Socket.connect(Socket.java:516)
  20. at java.net.Socket.connect(Socket.java:466)
  21. at java.net.Socket.<init>(Socket.java:366)
  22. at java.net.Socket.<init>(Socket.java:179)
  23. at com.sun.jndi.ldap.Connection.createSocket(Connection.java:346)
  24. at com.sun.jndi.ldap.Connection.<init>(Connection.java:181)
  25. ... 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
Similar Threads
Reputation Points: 10
Solved Threads: 0
Newbie Poster
Sukanto is offline Offline
7 posts
since Nov 2005
Mar 24th, 2007
0

Re: JNDI/JDBC lookup problem with Sun Java Application Server 8.2

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).
Team Colleague
Reputation Points: 1658
Solved Threads: 331
duckman
jwenting is offline Offline
7,719 posts
since Nov 2004
Mar 24th, 2007
0

Re: JNDI/JDBC lookup problem with Sun Java Application Server 8.2

Sorry jwenting, your solution didn't worked.
Reputation Points: 10
Solved Threads: 0
Newbie Poster
Sukanto is offline Offline
7 posts
since Nov 2005
Mar 24th, 2007
0

Re: JNDI/JDBC lookup problem with Sun Java Application Server 8.2

Can you please tell me whether there is any LDAP server provided with Sun Java Application Server 8.2 or not ? If not how do I connect a LDAP server (e.g. OpenLDAP) with SJAS 8.2 ???
Reputation Points: 10
Solved Threads: 0
Newbie Poster
Sukanto is offline Offline
7 posts
since Nov 2005

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in Java Forum Timeline: Java Simple calc
Next Thread in Java Forum Timeline: JFilerChooser default filefilter





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC