Home Page for the TeradataForum
 

Archives of the TeradataForum

Message Posted: Wed, 15 Oct 2003 @ 16:06:57 GMT


     
  <Prev Next>  
<<First
<Prev
Next>
Last>>
 


Subj:   Teradata JDBC Connection pool problem
 
From:   Sri Banda

I had written a Java singleton class to implement my Teradata Connection Pooling. I am able to configure the TeraConnetionPoolDataSource and retrieve it successfully. I am unable to get the connection from the TeraConnetionPoolDataSource. Can some one point out the problems in this code.

I am calling this class to get my connection.

     *****************
     DBConnectionFactory dbf = DBConnectionFactory.getInstance();
     Connection conn = dbf.getConnection();
     *****************

     public class DBConnectionFactory {
           private static DBConnectionFactory cFactory;
           private static TeraConnectionPoolDataSource ds;
           private static PooledConnection conn;
           private DBConfig dsProps;

           protected DBConnectionFactory() throws Exception {
                 try {
                       if (dsProps.getProperty("CONNECTION_POOL"
     ).equalsIgnoreCase("Yes")) {
                             createDataSource();
                             loadDataSource();
                       }
                 } catch (FileNotFoundException fnfe) {
                       throw fnfe;
                 } catch (IOException ioe) {
                       throw ioe;
                 }
           }

           private void loadDataSource() throws Exception {
                 Hashtable env = new Hashtable();
                 env.put(
                       Context.INITIAL_CONTEXT_FACTORY,
                  "com.sun.jndi.fscontext.RefFSContextFactory");
                 env.put(Context.PROVIDER_URL, dsProps.getProperty("PROVIDER_URL"));
                 try {
                       Context ctx = new InitialContext(env);
                       ds = (TeraConnectionPoolDataSource)
     ctx.lookup(dsProps.getProperty("JNDI"));
                       System.out.println(ds.getLoginTimeout());
                       conn = ds.getPooledConnection();
                       System.out.println(
                             "Established successful connection using DataSource");
                 } catch (NamingException ne) {
                       throw ne;
                 } catch (Exception e) {
                  throw e;
                 }
           }

           private void createDataSource() throws Exception {
                 Hashtable env2 = new Hashtable();
                 env2.put(
                       Context.INITIAL_CONTEXT_FACTORY,
                       "com.sun.jndi.fscontext.RefFSContextFactory");
                 env2.put(Context.PROVIDER_URL, dsProps.getProperty("PROVIDER_URL"));
                 try {
                       com.ncr.teradata.TeraConnectionPoolDataSource ds =
                             new
     com.ncr.teradata.TeraConnectionPoolDataSource
     ();

                       ds.setDSName(dsProps.getProperty("DSName"));
     //dataBase server name
                       ds.setdescription(dsProps.getProperty("Description"));

                       ds.setuser(dsProps.getProperty("User")); //user name
                       ds.setpassword(dsProps.getProperty("Password"));
     //password
                       ds.setdebugStr(dsProps.getProperty("Debug")); //debug
                       ds.setFetchRows(dsProps.getProperty("FetchRows"));
     //rcache

     ds.setTransactMode(dsProps.getProperty("TransactMode"));
     //tmode
                       ds.setCharSet(dsProps.getProperty("CharSet"));
     //charset
                       ds.setprint(dsProps.getProperty("Print"));

                       // SP_PRINT: PRINT = 1 NOPRINT = 2;
                       ds.setspl(dsProps.getProperty("Spool"));
                       // SP_SPL: SPL = 3, NOSPL = 4;

     ds.setDatabaseName(dsProps.getProperty("DataBaseName"));

                       Context ctx = new InitialContext(env2);
                       ctx.unbind(dsProps.getProperty("JNDI"));
                       ctx.bind(dsProps.getProperty("JNDI"), ds);
                       //known to users by this name
                 } catch (NamingException ne) {
                       System.out.println("HELP");
                       System.out.println("Exp: " + ne.getExplanation());
                       ne.printStackTrace();
                 }
           }

           public static DBConnectionFactory getInstance() throws Exception {
                 try {
                       if (cFactory == null)
                             cFactory = new DBConnectionFactory();
                 } catch (Exception e) {
                       throw e;
                 }
                 return cFactory;
           }

           public Connection getConnection() throws SQLException, Exception {
                 Connection con;
                 try {
                       if (dsProps.getProperty("CONNECTION_POOL"
     ).equalsIgnoreCase("Yes")) {
                             con = conn.getConnection();
                             return con;
                       } else {
                             String driverClass = dsProps.getProperty(
     "DRIVER_CLASS");
                             Class.forName(driverClass).newInstance();
                             con =
                                   DriverManager.getConnection(
                                         dsProps.getProperty("URL"),
                                         dsProps.getProperty("User"),
                                         dsProps.getProperty("Password"));
                             return con;
                       }
                 } catch (SQLException se) {
                       throw se;
                 } catch (Exception e) {
                       throw e;
                 }

           }

     }

Thanks

Sri Banda



     
  <Prev Next>  
<<First
<Prev
Next>
Last>>
 
 
 
 
 
 
 
 
 
  
  Top Home Privacy Feedback  
 
 
Copyright for the TeradataForum (TDATA-L), Manta BlueSky    
Copyright 2016 - All Rights Reserved    
Last Modified: 27 Dec 2016