The Artima Developer Community
Sponsored Link

Java Answers Forum
Database connection pooling

4 replies on 1 page. Most recent reply: Sep 1, 2002 9:00 PM by Rohit

Welcome Guest
  Sign In

Go back to the topic listing  Back to Topic List Click to reply to this topic  Reply to this Topic Click to search messages in this forum  Search Forum Click for a threaded view of the topic  Threaded View   
Previous Topic   Next Topic
Flat View: This topic has 4 replies on 1 page
Rohit

Posts: 38
Nickname: rohit
Registered: May, 2002

Database connection pooling Posted: Aug 26, 2002 1:37 AM
Reply to this message Reply
Advertisement
Hi Guys,
How to use javax.sql.ConnectctionPooldataSource and other connection pooling classes of javax.sql package without using JNDI,

I want to use Connection pooling in my application but dont want to go thru JNDI,

Any code example will be of gr8 help too,

Regards,
Rohit


Senthoorkumaran Punniamoorthy

Posts: 335
Nickname: senthoor
Registered: Mar, 2002

Re: Database connection pooling Posted: Aug 29, 2002 8:24 AM
Reply to this message Reply
import java.io.*;
import java.sql.*;
import javax.servlet.*;
import javax.servlet.http.*;
import javax.sql.*;
import oracle.jdbc.driver.*;
import oracle.jdbc.pool.*;

public class Pooljdbc2 extends HttpServlet{

private OracleConnectionPoolDataSource ocpds;
private OracleConnectionCacheImpl ods;

public void init(ServletConfig config) throws
ServletException {
super.init(config);
try {
ocpds =new OracleConnectionPoolDataSource();

ocpds.setURL("jdbc:oracle:thin:@bldel52:1522 :v816");

// ocpds.setUser("scott");
// ocpds.setPassword("tiger");

// Associate it with the Cache
ods = new OracleConnectionCacheImpl(ocpds);

// Set the Max Limit
ods.setMaxLimit (3);

// Set the Scheme
ods.setCacheScheme
(OracleConnectionCacheImpl.FIXED_RETURN_NULL_SCHEME);
}
catch (Exception e) {
throw new UnavailableException(this, "Couldn't
create connection pool");
}
}

public void doGet(HttpServletRequest req,
HttpServletResponse res)
throws
ServletException, IOException {
Connection con = null;
res.setContentType("text/plain");
PrintWriter out = res.getWriter();
out.println("Updating salary");

try {
con = ods.getConnection("scott","tiger");

// Turn on transactions
con.setAutoCommit(false);

Statement stmt = con.createStatement();
stmt.executeUpdate("UPDATE EMPBIG SET SAL =
(SAL - 10) ");
stmt.executeUpdate("UPDATE EMPBIG SET SAL =
(SAL + 10) ");

con.commit();

out.println("Salary updated");

con.close();
}
catch (Exception e) {

// Any error is grounds for rollback
try {
con.rollback();
}
catch (Exception ignored) { }
out.println("No more connections available,
try later");
}
}

public void destroy() {

try {
ods.close();
}
catch (Exception ignored) { }
}
}

Hope this helps you....

Rohit

Posts: 38
Nickname: rohit
Registered: May, 2002

Re: Database connection pooling Posted: Aug 29, 2002 11:02 PM
Reply to this message Reply
Is there any way to make it database independent? I have changed this to fit in my case(db2) , but i want to make it database independet,i dont want to specifially user oracepool or db2 pool classes.

Thanks for ur reply.

Don Hill

Posts: 70
Nickname: ssswdon
Registered: Jul, 2002

Re: Database connection pooling Posted: Aug 30, 2002 7:48 AM
Reply to this message Reply
> Hi Guys,
> How to use
> to use javax.sql.ConnectctionPooldataSource and other
> connection pooling classes of javax.sql package
> without using JNDI,
>
> I want to use Connection pooling in my application
> on but dont want to go thru JNDI,
>
> Any code example will be of gr8 help too,
>
> Regards,
> Rohit

Just curious, in what context are you using this connections, swing, appserver .....

If you are doing this on the client side I think its a bit of overkill, in the appserver world you would have the server manage the connection pooling and best practice is to use the jndi datasource because this hides the db.

-Don-
Maybe

Rohit

Posts: 38
Nickname: rohit
Registered: May, 2002

Re: Database connection pooling Posted: Sep 1, 2002 9:00 PM
Reply to this message Reply
I want a connection to an underlying database from an proxy , which has been downloaded by an JINI client, I m afraid but i dont have the luxury or necessisty for appserver just to do d/b pooling as i dont require it for anything else.

So any ideas of the above prob.

Flat View: This topic has 4 replies on 1 page
Topic: job interview questions on java Previous Topic   Next Topic Topic: what does remote refrence layer do in rmi

Sponsored Links



Google
  Web Artima.com   

Copyright © 1996-2019 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use