Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

IBM Websphere 5 Connection Pool

 
Imad Uddin Chishti
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Can someone please reconfigure following code for Websphere 5. This code is for websphere 3.5
package cfas;
import java.sql.*;
import java.util.*;
import javax.sql.*;
import com.ibm.ejs.dbm.jdbcext.*;
import javax.naming.*;
public class ConnectionPool{
private static DataSource ds = null;
private static Connection conn=null;
private static Context ctx;
private static int firstTime = 0;
public static synchronized Connection getConnection() throws SQLException
{
try {
if ( firstTime == 0 )
{
firstTime = 1;
Hashtable parms = new Hashtable();
parms.put(Context.INITIAL_CONTEXT_FACTORY,"com.ibm.ejs.ns.jndi.CNInitialContextFactory");
ctx = new InitialContext(parms);
ds = (DataSource)ctx.lookup("jdbc/DB2TST01");
}
conn = ds.getConnection("saz","saz");
conn.setAutoCommit(true);
}
catch (Exception e ) { System.out.println("connection()Naming execption:" + e.getMessage()); }
return conn;
}
public static synchronized void freeConnection(Connection back)
{
try {back.close();}
catch (SQLException e) { System.out.println("Close Time Exactly()"+e.getMessage());}
}
}
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic