0 Replies Latest reply on Apr 15, 2003 7:30 AM by pinky

    lookup problem

    pinky Newbie

      Hi,
      I have installed jboss3.2 on linux. i have put sqlserver type 4 driver jar file in server lib folder.

      i am not able to lookup the JNDI name java://MSSQL.

      Not only the datasource JNDI, I am not able lookup any bean JNDI also. When i do lookup i am getting NullPointerException.

      following is the code
      import javax.sql.*;
      import java.sql.*;
      import javax.naming.*;
      import java.util.*;
      /**
      * Microsoft SQL Server JDBC test program
      */
      public class ConnectSQL
      {

      public ConnectSQL() {
      // Get connection
      System.out.println("Kaladhar-1");
      try
      {
      //Class.forName("net.sourceforge.jtds.jdbc.Driver");

      Connection connection = getConnection("java:/MSSQL");
      System.out.println("Kaladhar-3" );
      if (connection != null)
      {
      System.out.println();
      System.out.println("Successfully connected");
      System.out.println();
      // Meta data
      DatabaseMetaData meta = connection.getMetaData();
      System.out.println("\nDriver Information");
      System.out.println("Driver Name: "
      + meta.getDriverName());
      System.out.println("Driver Version: "
      + meta.getDriverVersion());
      System.out.println("\nDatabase Information ");
      System.out.println("Database Name: "
      + meta.getDatabaseProductName());
      System.out.println("Database Version: "+
      meta.getDatabaseProductVersion());
      }
      }catch (Exception e)
      {
      e.printStackTrace();
      }
      } // Test
      public static void main (String args[]) throws Exception
      {
      ConnectSQL cSQL = new ConnectSQL();
      }

      private Connection getConnection(String SPoolName)
      {
      Connection conn = null;
      Statement st = null;
      ResultSet rs = null;
      DataSource ds = null;
      InitialContext ctx = null;
      try
      {
      Properties prop = new Properties();
      prop.put(Context.INITIAL_CONTEXT_FACTORY,"org.jnp.interfaces.NamingContextFactory");
      //prop.put(Context.PROVIDER_URL,"jnp://192.168.175.42:1099");
      prop.put(Context.URL_PKG_PREFIXES,"org.jboss.naming:org.jnp.interfaces");
      ctx = new InitialContext(prop);
      System.out.println("OBJECT---" + ctx);
      //ctx = new InitialContext();
      ds =(DataSource)ctx.lookup(SPoolName);
      System.out.println("OBJECT DS" + ds);
      conn = ds.getConnection();
      System.out.println("OBJECT" + conn);

      //System.out.println("From cDBAccess.getConnection(), poolname: " +
      // SPoolName + " Datasource is: " + ds + " Connection is: " + conn);
      }
      catch(NamingException e)
      {
      //System.out.println("Naming Exception while getting connection...1");
      System.out.println("EXCEPTION IN DBACCESS DB NAMING EXCEPTION:"+e.getMessage());
      e.printStackTrace();
      }
      catch(SQLException ex)
      {
      //System.out.println("Exception while getting connection...2");
      System.out.println("EXCEPTION IN DBACCESS LOOKUP:"+ex.getMessage());
      ex.printStackTrace();
      }catch(Exception e)
      {
      System.out.println("EXCEPTION IN Kaladhar:");
      e.printStackTrace();
      }

      return conn;
      }//end of getConnection()
      }

      rgds
      -kaladhar