• Post Reply Bookmark Topic Watch Topic
  • New Topic

I am unable to create initialcontext obejct  RSS feed

ramakoteswararao siddabad
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am using eclipse 3.1 version,java1.4.1 version.

i am unable create the initialcontext obejct . I have written the following code.
public static void main(String[] args) throws NamingException, SQLException {

Hashtable props = new Hashtable();
InitialContext ctx = new InitialContext();
DataSource d=(DataSource)ctx.lookup("DataSource");
Connection con=d.getConnection();
Statement s=con.createStatement();
ResultSet rs = s.executeQuery("select * from emp");
ResultSetMetaData m=rs.getMetaData();

i am getting following error:

javax.naming.CommunicationException: localhost:389 [Root exception is java.net.ConnectException: Connection refused: connect]
at com.sun.jndi.ldap.Connection.<init>(Unknown Source)
at com.sun.jndi.ldap.LdapClient.<init>(Unknown Source)
at com.sun.jndi.ldap.LdapClient.getInstance(Unknown Source)
at com.sun.jndi.ldap.LdapCtx.connect(Unknown Source)
at com.sun.jndi.ldap.LdapCtx.<init>(Unknown Source)
at com.sun.jndi.ldap.LdapCtxFactory.getUsingURL(Unknown Source)
at com.sun.jndi.ldap.LdapCtxFactory.getUsingURLs(Unknown Source)
at com.sun.jndi.ldap.LdapCtxFactory.getLdapCtxInstance(Unknown Source)
at com.sun.jndi.ldap.LdapCtxFactory.getInitialContext(Unknown Source)
at javax.naming.spi.NamingManager.getInitialContext(Unknown Source)
at javax.naming.InitialContext.getDefaultInitCtx(Unknown Source)
at javax.naming.InitialContext.init(Unknown Source)
at javax.naming.InitialContext.<init>(Unknown Source)
at JndiConnection.main(JndiConnection.java:35)
Caused by: java.net.ConnectException: Connection refused: connect
at java.net.PlainSocketImpl.socketConnect(Native Method)
at java.net.PlainSocketImpl.doConnect(Unknown Source)
at java.net.PlainSocketImpl.connectToAddress(Unknown Source)
at java.net.PlainSocketImpl.connect(Unknown Source)
at java.net.Socket.connect(Unknown Source)
at java.net.Socket.connect(Unknown Source)
at java.net.Socket.<init>(Unknown Source)
at java.net.Socket.<init>(Unknown Source)
at com.sun.jndi.ldap.Connection.createSocket(Unknown Source)
... 14 more

Could you please give me advice to go head in this issue.
Mark Spritzler
Posts: 17309
IntelliJ IDE Mac Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have closed your duplicate thread below. Please refrain from posting duplicates.

Consider Paul's rocket mass heater.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!