• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Websphere Connection Pooling

 
Balbir Singh
Ranch Hand
Posts: 79
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What support does Websphere 3.5 provide for connection pooling while using JSP's.
 
Heath Lilley
Ranch Hand
Posts: 72
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Websphere 3.5 has full support for JNDI and DataSources. We have 2 apps running with no problems.
You just need to use IBMs context factory class.
And have your Database Drivers in the class path for the current webapp you are working on.
 
Balbir Singh
Ranch Hand
Posts: 79
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Thanks for the reply.

I have made up a datasource name OraTest through Admin Console in Websphere and written the code given below. The problem is I am not able to compile it since its not finding the javax.sql.* packageg. If you can pls help:

import javax.servlet.*;
import javax.servlet.http.*;
import java.io.*;
import java.sql.*;
import java.util.*;
import javax.sql.*;

public class ConPoolextends HttpServlet{
public void doGet(HttpServletRequest req, HttpServletResponse res)throws ServletException, IOException{
res.setContentType("text/html");
PrintWriter out = res.getWriter();
Connection conn=null;
Statement stmt=null;
ResultSet rs=null;
try{
Properties prop = new Properties();
prop.put(DataSourceFactory.NAME, "OraTest");
prop.put(DataSourceFactory.DATASOURCE_CLASS_NAME, "oracle\jdbc\pool\OraclePooledConnection");
prop.put(DataSourceFactory.DESCRIPTION, " Connection Pooling using Oracle thin driver");
prop.put("pslndb","sample");
DataSource ds=DataSourceFactory.getDataSource(prop);
DataSourceFactory.bindDataSource(ds);
}
catch(Exception e){
e.getMessage();
}

try{
Hashtable env=new Hashtable();
env.put(Context.INITIAL_CONTEXT_FACTORY,"com.ibm.ejs.ns.jndi.CNInitialContextFactory");
javax.naming.Context ctx = new javax.naming.InitialContext(env);
javax.sql.DataSource ds = (javax.sql.DataSource)ctx.lookup("jdbc/OraTest");
conn=ds.getConnection("Smsadm","Sms$adm");
stmt=conn.createStatement();
rs=stmt.executeQuery("Select * from tb_users");
while(rs.next()){
out.println(rs.getString(1));
}
}
catch(Exception e){
out.println(e.getMessage());
}
}
}

 
Balbir Singh
Ranch Hand
Posts: 79
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I got the thing working.
Thanks
 
Joe Nguyen
Ranch Hand
Posts: 161
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Just for those who do not know the solution. You need to import the project/or package into your workbench.
 
Ram Kondawar
Ranch Hand
Posts: 42
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi
Can you please tell me why you require the code pertaining to the creation of the datasource is required in the servlet, after you have configured the datasource in admin console.
Can't we straight away do the lookup and get the datasource in the servlet code. Please clarify.
Thanks in advance
Ram Kondawar
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic