Win a copy of Think Java: How to Think Like a Computer Scientist this week in the Java in General forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Sun one application server and connection pool

 
ben ku
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
I'm using SunOne AS7 and a mysql DB. I have a Java class that does all the work with the DB :

and so on.
I would like to use a connection pool but I don't know how to do that. On the admin pages of the app server, I've added a connection pool in Server1/JDBC/Connection Pools and I would like to know what I have to change in my code to use this connection pool.
thanks
 
Maulin Vasavada
Ranch Hand
Posts: 1873
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi ben,
On Sun One,
Here is what I think should work,
1. First you have to configure connection pool as you already did
2. Configure "JDBC Resources" where you have to choose Connection Pool
and "JNDI Name" for the JDBC Resource ..e.g. jdbc/myJDBCResource
3. Use this JNDI Name to obtain the connection via,
java.sql.DataSource ds = (java.sql.DataSource)lookup("java:comp/env/jdbc/myJDBCResource");
Connection con = ds.getConnection();
....
...rest you know...
Also, look at this link, it should help you to see how to configure "resource-ref" entry in appropriate place like web.xml,sun-web.xml...
Regards
Maulin
 
Maulin Vasavada
Ranch Hand
Posts: 1873
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi ben,
also, from stand alone class it might not work as for stand alone class where would we configure "resource-ref" you know Anybody else knows if this can work? I am not yet an expert with Sun ONE...
you might have to create a servlet or jsp or session bean to do the operation...
Regards
Maulin
 
Maulin Vasavada
Ranch Hand
Posts: 1873
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
from the stand alone client you might have to drop java:comp/env from the lookup path and then use PROVIDER_URL and INITIAL_CONTEXT_FACTORY attributes set in the Conext env just as any other remote client...but I am not sure if it would work for jdbc resource...
Regards
Maulin
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic