Problem in accessing Data Source Deployed in JBoss using JNDI

Discussions

General J2EE: Problem in accessing Data Source Deployed in JBoss using JNDI

  1. Hi, I have installed MySql in my laptop. In the same laptop I am running my JBoss application server. I have created a data source to connect to my MySql data base using the following entry in mysql-ds.xml MySqlDS false jdbc:mysql://localhost:3306/jboss com.mysql.jdbc.Driver jboss password I am able to create a new data base into the MySql database mentioned above. Now I am executing the following java code to access the MySql data base using the data source created in JBoss: private static void testDataSource()throws NamingException, SQLException { final String sql = "select version()"; Hashtable ht=new Hashtable(); ht.put(InitialContext.INITIAL_CONTEXT_FACTORY,"org.jnp.interfaces.NamingContextFactory"); ht.put(InitialContext.PROVIDER_URL,"jnp://localhost:1099"); ht.put(InitialContext.URL_PKG_PREFIXES,"org.jboss.naming:org.jnp.interfaces"); InitialContext ic=new InitialContext(ht); if(ic!=null) System.out.println("Initial Context success"); DataSource ds=(DataSource)ic.lookup("MySqlDS"); if(ds!=null) System.out.println("Data Source success"); Connection con = null; Statement stmt = null; ResultSet rs = null; try { con = ds.getConnection(); stmt = con.createStatement(); rs = stmt.executeQuery(sql); while(rs.next()) { System.out.println("Query '" + sql + "' returned " + rs.getString(1)); } } finally { if(rs != null) rs.close(); if(stmt != null) stmt.close(); if(con != null) con.close(); } } This code is working fine. I am getting the following output: Query 'select version()' returned 5.0.51b-community-nt But when I am uing my machine IP or the machine name instead of "localhost" in the following line then it is not working: InitialContext.PROVIDER_URL,"jnp://<>:1099" I am getting the following exception: Initial Context success log4j:WARN No appenders could be found for logger (org.jnp.interfaces.NamingContext). log4j:WARN Please initialize the log4j system properly. Exception in thread "main" javax.naming.CommunicationException: Could not obtain connection to any of these urls: GLN113 67:1099 and discovery failed with error: javax.naming.CommunicationException: Receive timed out [Root exception is java. net.SocketTimeoutException: Receive timed out] [Root exception is javax.naming.CommunicationException: Failed to connect to server GLN11367:1099 [Root exception is javax.naming.ServiceUnavailableException: Failed to connect to server GLN113 67:1099 [Root exception is java.net.ConnectException: Connection refused: connect]]] at org.jnp.interfaces.NamingContext.checkRef(NamingContext.java:1562) at org.jnp.interfaces.NamingContext.lookup(NamingContext.java:634) at org.jnp.interfaces.NamingContext.lookup(NamingContext.java:627) at javax.naming.InitialContext.lookup(Unknown Source) at DataSourceTest.testDataSource(DataSourceTest.java:50) at DataSourceTest.main(DataSourceTest.java:12) Caused by: javax.naming.CommunicationException: Failed to connect to server GLN11367:1099 [Root exception is javax.namin g.ServiceUnavailableException: Failed to connect to server GLN11367:1099 [Root exception is java.net.ConnectException: C onnection refused: connect]] at org.jnp.interfaces.NamingContext.getServer(NamingContext.java:274) at org.jnp.interfaces.NamingContext.checkRef(NamingContext.java:1533) ... 5 more Caused by: javax.naming.ServiceUnavailableException: Failed to connect to server GLN11367:1099 [Root exception is java.n et.ConnectException: Connection refused: connect] at org.jnp.interfaces.NamingContext.getServer(NamingContext.java:248) ... 6 more 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.SocksSocketImpl.connect(Unknown Source) at java.net.Socket.connect(Unknown Source) at java.net.Socket.connect(Unknown Source) at java.net.Socket.(Unknown Source) at java.net.Socket.(Unknown Source) at org.jnp.interfaces.TimedSocketFactory.createSocket(TimedSocketFactory.java:84) at org.jnp.interfaces.TimedSocketFactory.createSocket(TimedSocketFactory.java:77) at org.jnp.interfaces.NamingContext.getServer(NamingContext.java:244) ... 6 more Can anyone please let me know how can I resolve this problem. I am working on this problem for last 3 days and not able to resolve it. I have also searched the web but not able to find any resolution to this particular type of problem. Additional Information: 1) I am able to see the JBoss admin console using the following URL: http://localhost:8080/. But it is saying "The page cannot be displayed" when I am using my laptop IP address or computer name. Any help will be appriciated. Thanks, Raj Kumar
  2. When you start jboss, use "run.sh -b 0.0.0.0". By default, jboss is secure and bound to localhost only.
  3. Hi John, Your solution worked like a magic. Now I can access my JBoss admin and JMX console using the following URL: http://:8080/ and the problem of accessing the datasource deployed in JBoss from a remote machine using the previously mentioned java code has also been resolved by this. Now I can access the datasource deployed in JBoss from remote machine to get a java.sql.Connection from a connection pool. Thanks for your help and value addition. Thanks & Regards, Raj Kumar Kundu
  4. problem in accessing network database[ Go to top ]

    Hi,

    I am connecting SQL Server in local networkMy application is working fine whether the network is proper. In case If I disconnect my network and reconnect, it will throw com.microsoft.sqlserver.jdbc.SQLServerException: The connection is closed error

    Jboss log returns 

    [org.jnp.interfaces.NamingContext] Failed to connect to user1:1099 javax.naming.CommunicationException: Failed to connect to server user1:1099 [Root exception is javax.naming.ServiceUnavailableException: Failed to connect to server user1:1099 [Root exception is  java.net.UnknownHostException: user1]]