Home Page for the TeradataForum
 

Archives of the TeradataForum

Message Posted: Tue, 23 Sep 2003 @ 15:15:15 GMT


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


Subj:   Re: Connection pool in WebSphere??
 
From:   Devendra_Nath

Hello

Teradata JDBC Drivers can be used with any Version of IBM WebSphere , here is the sample code to use a connection from the connection pool created in the websphere

import javax.naming.*;
import java.sql.*;
import java.io.*;
import javax.sql.*;
import java.util.Hashtable;
class ConnectDS
{
        static Connection con = null;
        public static void main(String[] args)
        {

        java.util.Properties parms = new java.util.Properties();

parms.setProperty(Context.INITIAL_CONTEXT_FACTORY,"com.ibm.websphere.naming.WsnInitialContextFactory");
        parms.put(Context.PROVIDER_URL, "iiop://localhost:900");
                try
                {
                        DriverManager.setLogStream(new PrintStream(new FileOutputStream("driver.log")));
                        Context ctx = new InitialContext(parms);
                        DataSource ds = (DataSource) ctx.lookup("SampleDataSource");
                        con = ds.getConnection("weekly", "weekly");
                        System.out.println("Established successful connection using DataSource");
                        CloseCon();
                }
                catch (SQLException se)
                {
                        SQLExHandler(se);
                }
                catch (NamingException ne)
                {
                        ne.printStackTrace();
                }
                catch (Exception e)
                {
                        e.printStackTrace();
                }
        }
        private static void CloseCon()
        {
                System.out.println("Closing Connection");
                try
                {
                        con.close();
                        System.out.println("Disconnected");
                }
                catch(SQLException ex)
                {
                        System.out.println("Problem Closing Connection");
                }
        }

        private static void SQLExHandler (SQLException ex)
        {
                System.out.println ("\n*** SQLException caught ***\n");
                while (ex != null)
                {
                System.out.println ("SQLState: " +ex.getSQLState ());
                System.out.println ("Message:  " +ex.getMessage ());
                System.out.println ("Vendor:   " +ex.getErrorCode ());
                ex = ex.getNextException ();
                System.out.println ("");
                }
        }
}


     
  <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: 15 Jun 2023