Search...
FAQs
Subscribe
Pie
FAQs
Recent topics
Flagged topics
Hot topics
Best topics
Search...
Search within JDBC and Relational Databases
Search Coderanch
Advance search
Google search
Register / Login
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
Pie Elite
all forums
this forum made possible by our volunteer staff, including ...
Marshals:
Campbell Ritchie
Jeanne Boyarsky
Ron McLeod
Paul Clapham
Liutauras Vilda
Sheriffs:
paul wheaton
Rob Spoor
Devaka Cooray
Saloon Keepers:
Stephan van Hulst
Tim Holloway
Carey Brown
Frits Walraven
Tim Moores
Bartenders:
Mikalai Zaikin
Forum:
JDBC and Relational Databases
get Connection from ConnectionPool
sai prasanna
Ranch Hand
Posts: 167
posted 17 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
hi all,
How to get an Connection from an Connnection Pool is the following code correct.
Connection con=null;
con = ds.getConnection();
thanks in advance
saiprasanna.
Wei Dai
Ranch Hand
Posts: 86
posted 17 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
ConnectionPoolDataSource ds;
//...
PooledConnection con=ds.getPooledConnection();
Masoud Kalali
Author
Posts: 531
I like...
posted 17 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
sai prasanna
, you code is true in case that your datasource works ok , do not forget that you must close the connection after your job finished with the connection.
What
Wei Dai
said , must looks like the following one to works.
ConnectionPoolDataSource cpds = new ConnectionPoolDataSource(); cpds.setServerName("127.0.0.1"); cpds.setDatabaseName("db1"); cpds.setPortNumber(3306); cpds.setDescription("sampleDatabase"); Context ctx = new InitialContext(); ctx.bind("jdbc/pool/db1 ", cpds); PooledDataSource ds = new PooledDataSource(); ds.setDescription("my sample pooled datasource"); ds.setDataSourceName("jdbc/pool/db1"); Context ctx = new InitialContext(); ctx.bind("jdbc/db1", ds); DataSource ds = (DataSource)ctx.lookup("jdbc/db1"); Connection con = ds.getConnection("myUserName", "myPassword");
Masoud Kalali
Software Engineer -
My Weblog
-
GlassFish Security
Don't get me started about those stupid
light bulbs
.
reply
reply
Bookmark Topic
Watch Topic
New Topic
Boost this thread!
Similar Threads
connection object question
How to use ConnectionPool in jsp
CommunicationsException and Connection Pooling
How to get SQLServerDataSource reference....
About HttpurlConnection.java
More...