JNDI/JDBC lookup problem with Sun Java Application Server 8.2

Reply

Join Date: Nov 2005
Posts: 7
Reputation: Sukanto is an unknown quantity at this point 
Solved Threads: 0
Sukanto's Avatar
Sukanto Sukanto is offline Offline
Newbie Poster

JNDI/JDBC lookup problem with Sun Java Application Server 8.2

 
0
  #1
Mar 22nd, 2007
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:
  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:
  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
Reply With Quote Quick reply to this message  
Join Date: Nov 2004
Posts: 6,143
Reputation: jwenting is just really nice jwenting is just really nice jwenting is just really nice jwenting is just really nice 
Solved Threads: 213
Team Colleague
jwenting's Avatar
jwenting jwenting is offline Offline
duckman

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

 
0
  #2
Mar 24th, 2007
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).
As people are clearly allowed to attack me but I'm not allowed to defend myself, I no longer post to this site.
Reply With Quote Quick reply to this message  
Join Date: Nov 2005
Posts: 7
Reputation: Sukanto is an unknown quantity at this point 
Solved Threads: 0
Sukanto's Avatar
Sukanto Sukanto is offline Offline
Newbie Poster

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

 
0
  #3
Mar 24th, 2007
Sorry jwenting, your solution didn't worked.
Reply With Quote Quick reply to this message  
Join Date: Nov 2005
Posts: 7
Reputation: Sukanto is an unknown quantity at this point 
Solved Threads: 0
Sukanto's Avatar
Sukanto Sukanto is offline Offline
Newbie Poster

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

 
0
  #4
Mar 24th, 2007
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 ???
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC