Win a copy of TensorFlow 2.0 in Action this week in the Artificial Intelligence and Machine Learning forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Paul Clapham
  • Bear Bibeault
  • Jeanne Boyarsky
Sheriffs:
  • Ron McLeod
  • Tim Cooke
  • Devaka Cooray
Saloon Keepers:
  • Tim Moores
  • Tim Holloway
  • Jj Roberts
  • Stephan van Hulst
  • Carey Brown
Bartenders:
  • salvin francis
  • Scott Selikoff
  • fred rosenberger

Websphere Connection Pooling

 
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.
 
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
 
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.
 
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
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic