wood burning stoves 2.0*
The moose likes Websphere and the fly likes Websphere Connection Pooling Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of OCA/OCP Java SE 7 Programmer I & II Study Guide this week in the OCPJP forum!
JavaRanch » Java Forums » Products » Websphere
Bookmark "Websphere Connection Pooling" Watch "Websphere Connection Pooling" New topic
Author

Websphere Connection Pooling

Balbir Singh
Ranch Hand

Joined: Jun 01, 2001
Posts: 79
What support does Websphere 3.5 provide for connection pooling while using JSP's.


Thanks and Regards<br />Balbir Singh<br />Sun Certified Java Programmer<br />IBM Certified Administrator for WebSphere4.0
Heath Lilley
Ranch Hand

Joined: Jan 09, 2001
Posts: 72
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

Joined: Jun 01, 2001
Posts: 79

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

Joined: Jun 01, 2001
Posts: 79
I got the thing working.
Thanks
Joe Nguyen
Ranch Hand

Joined: Apr 20, 2001
Posts: 161
Just for those who do not know the solution. You need to import the project/or package into your workbench.
Ram Kondawar
Ranch Hand

Joined: May 29, 2001
Posts: 42
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
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Websphere Connection Pooling