1 Reply Latest reply on Aug 2, 2003 8:47 AM by jonlee

    Problem in connecting with MSSQL Server 2000

    harpreetset

      Hi,
      I have installed jboss-3.2.1_tomcat-4.1.24 on my system. I want to connect to MS SQL Server 2000 database available on a different. I have changed mssql-ds.xml as follows

      <local-tx-datasource>
      <jndi-name>mySQLServerPool</jndi-name>
      <connection-url>jdbc:microsoft:sqlserver://192.168.100.12:1433;DatabaseName=EOTSTORE</connection-url>
      <driver-class>com.microsoft.jdbc.sqlserver.SQLServerDriver</driver-class>
      <user-name>sa</user-name>
      sa
      </local-tx-datasource>

      as pasted it all\deploy directory.

      I got the following message on Server console which i think says that datasource deployed successfully.

      19:06:01,734 INFO [MainDeployer] Starting deployment of package: file:/C:/jboss
      -3.2.1_tomcat-4.1.24/server/all/deploy/mssql-ds.xml
      19:06:01,765 INFO [XSLSubDeployer] transformed into doc: [#document: null]
      19:06:01,781 INFO [RARDeployment] Creating
      19:06:01,781 INFO [RARDeployment] Created
      19:06:01,781 INFO [JBossManagedConnectionPool] Creating
      19:06:01,781 INFO [JBossManagedConnectionPool] Created
      19:06:01,781 INFO [TxConnectionManager] Creating
      19:06:01,781 INFO [TxConnectionManager] Created
      19:06:01,796 INFO [RARDeployment] Starting
      19:06:01,796 INFO [RARDeployment] Started
      19:06:01,796 INFO [JBossManagedConnectionPool] Starting
      19:06:01,796 INFO [JBossManagedConnectionPool] Started
      19:06:01,796 INFO [TxConnectionManager] Starting
      19:06:01,812 INFO [mySQLServerPool] Bound connection factory for resource adapt
      er for ConnectionManager 'jboss.jca:service=LocalTxCM,name=mySQLServerPool to JN
      DI name 'java:/mySQLServerPool'
      19:06:01,812 INFO [TxConnectionManager] Started
      19:06:01,812 INFO [MainDeployer] Deployed package: file:/C:/jboss-3.2.1_tomcat-
      4.1.24/server/all/deploy/mssql-ds.xml

      I am using the following program to access database through Datasource.

      import java.sql.*;
      import java.util.*;
      import javax.naming.*;




      public class simplesql {

      public static void main(String argv[])
      throws Exception
      {
      java.sql.Connection conn = null;
      java.sql.Statement stmt = null;
      try {

      // ============== Make connection to database ==================
      // Obtain a Datasource connection from the WebLogic JNDI tree.
      Context ctx = null;

      // Put connection properties in to a hashtable.
      Hashtable props = new Hashtable();
      props.put(Context.INITIAL_CONTEXT_FACTORY,"org.jnp.interfaces.NamingContextFactory");
      props.put(Context.PROVIDER_URL, "jnp://localhost:1099/");
      props.put("java.naming.rmi.security.manager", "yes");
      props.put(Context.URL_PKG_PREFIXES, "org.jboss.naming");

      // Get a context for the JNDI look up
      ctx = new InitialContext(props);
      System.out.println("got the context "+ctx);
      javax.sql.DataSource ds
      = (javax.sql.DataSource) ctx.lookup ("java:/mySQLServerPool");
      conn = ds.getConnection();
      System.out.println("Making connection...\n");

      // execute some SQL statements to demonstrate the connection.
      stmt = conn.createStatement();

      try {
      stmt.execute("drop table empdemo");
      System.out.println("Table empdemo dropped.");
      } catch (SQLException e) {
      System.out.println("Table empdemo doesn't need to be dropped.");
      }

      stmt.execute("create table empdemo (empid int, name varchar(30), dept int)");
      System.out.println("Table empdemo created.");

      int numrows = stmt.executeUpdate("insert into empdemo values (0, 'John Smith', 12)");
      System.out.println("Number of rows inserted = " + numrows);

      numrows = stmt.executeUpdate("delete from empdemo where empid = 0");
      System.out.println("Number of rows deleted = " + numrows);
      } catch (Exception e) {
      System.out.println("Exception was thrown: " + e.getMessage());
      e.printStackTrace();
      } finally {
      try {
      if (stmt != null)
      stmt.close();
      if (conn != null)
      conn.close();
      } catch (SQLException sqle) {
      System.out.println("SQLException during close(): " + sqle.getMessage());
      }
      }
      }

      }

      The code is compiling perfectly, but while running i am getting the following error:


      Exception was thrown: mySQLServerPool not bound
      javax.naming.NameNotFoundException: mySQLServerPool not bound
      at org.jnp.server.NamingServer.getBinding(NamingServer.java:495)
      at org.jnp.server.NamingServer.getBinding(NamingServer.java:503)
      at org.jnp.server.NamingServer.getObject(NamingServer.java:509)
      at org.jnp.server.NamingServer.lookup(NamingServer.java:282)
      at sun.reflect.GeneratedMethodAccessor50.invoke(Unknown Source)
      at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAcces
      sorImpl.java:25)
      at java.lang.reflect.Method.invoke(Method.java:324)
      at sun.rmi.server.UnicastServerRef.dispatch(UnicastServerRef.java:261)
      at sun.rmi.transport.Transport$1.run(Transport.java:148)
      at java.security.AccessController.doPrivileged(Native Method)
      at sun.rmi.transport.Transport.serviceCall(Transport.java:144)
      at sun.rmi.transport.tcp.TCPTransport.handleMessages(TCPTransport.java:4
      60)
      at sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.run(TCPTransport
      .java:701)
      at java.lang.Thread.run(Thread.java:536)
      at sun.rmi.transport.StreamRemoteCall.exceptionReceivedFromServer(Stream
      RemoteCall.java:247)
      at sun.rmi.transport.StreamRemoteCall.executeCall(StreamRemoteCall.java:
      223)
      at sun.rmi.server.UnicastRef.invoke(UnicastRef.java:133)
      at org.jnp.server.NamingServer_Stub.lookup(Unknown Source)
      at org.jnp.interfaces.NamingContext.lookup(NamingContext.java:492)
      at org.jnp.interfaces.NamingContext.lookup(NamingContext.java:471)
      at javax.naming.InitialContext.lookup(InitialContext.java:347)
      at simplesql.main(simplesql.java:43)


      Please help me to solve this problem.
      Do i need to do more configuration for deploying Datastore on Jboss

      regards
      Harpreet

        • 1. Re: Problem in connecting with MSSQL Server 2000
          jonlee

          You cannot access a datasource from outside the JVM that is running JBoss. WebLogic provides a proxy implementation for datasources that allows remote clients to access a datasource by connecting to the WebLogic infrastructure that then connects to the datasource, as far as I understand their implementation.

          You can access JBoss datasources from EJBs or servlets/JSPs running in the embedded Jetty/Tomcat.