0 Replies Latest reply on Sep 29, 2003 8:24 AM by saed

    Deploy a DataSource object

    saed Newbie

      Hi All

      how can i deploy a Datasource object? i am using JBoss 3.0.4.

      when i am using the following code i am getting a null exception when i am trying to get a connection object from the DataSource object. So could anyone tell what is the problem



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

      public class ConnectionPoolTest implements Serializable
      {
      public ConnectionPoolTest()
      {
      try
      {
      Context context = new InitialContext();
      PooledDataSource ds = new PooledDataSource();
      ds.setDatabaseName("mydirectoffice");
      ds.setServerName("localhost");
      ds.setPassword("");
      ds.setUser("");
      ds.getConnection().close();
      }
      catch(Exception e)
      {
      System.out.println(e.toString());
      }
      }


      class PooledDataSource implements DataSource, Serializable
      {
      private Connection connection = null;
      private PrintWriter printWriter = null;
      private int timeOut = 10;
      private String user = "";
      private String password = "";
      private String databaseName = "";
      private String serverName = "";
      public Connection getConnection()
      {
      return connection;
      }

      public String getUser()
      {
      return user;
      }

      public void setUser(String user)
      {
      this.user = user;
      }

      public String getPassword()
      {
      return password;
      }

      public void setPassword(String password)
      {
      this.password = password;
      }

      public String getDatabaseName()
      {
      return databaseName;
      }

      public void setDatabaseName(String databaseName)
      {
      this.databaseName = databaseName;
      }

      public String getServerName()
      {
      return serverName;
      }

      public void setServerName(String serverName)
      {
      this.serverName = serverName;
      }

      public Connection getConnection(String userName, String password)
      {
      return connection;
      }

      public int getLoginTimeout()
      {
      return timeOut;
      }

      public void setLoginTimeout(int timeOut)
      {
      this.timeOut = timeOut;
      }

      public PrintWriter getLogWriter()
      {
      return printWriter;
      }

      public void setLogWriter(PrintWriter printWriter)
      {
      this.printWriter = printWriter;
      }
      }
      }




      thank you