wood burning stoves*
The moose likes JDBC and the fly likes Getting pooled connection using DSN Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Databases » JDBC
Bookmark "Getting pooled connection using DSN" Watch "Getting pooled connection using DSN" New topic
Author

Getting pooled connection using DSN

Shitij Bhargava
Greenhorn

Joined: Jun 17, 2010
Posts: 10
Hi !

I am making a connection class in which a method getConnection(dsn,username,password) is there, which returns a connection object.

See the following code, it works : (both the commented and the uncommented ways to get connection). The commented way gets an unpooled connection, but uses the dsn so I dont have to hardcode anything (but I want connection pooling) and if I use the uncommented way, I get a pooled connection but, I have to hardcode the server name and Database name. I dont want to hardcode these. I want to get them through the dsn I've made.





I know I cant access dsn info from java code directly (without using jni probably), so I tried to use the setURL() method in the following way:
(this is my attempt to do what I want, but it doesnt work)

But this gives SQLException saying: The connection string contains a badly formed name or value.
The only thing I can infer from this is that the url in DriverManager.getConnection(String url) and the url in SQLServerConnectionPooledDataSource#setURL(String url) are different in some way.
Then what should I put as url here in setURL() ?? (such a url which uses the dsn name, and I dont have to hardcode server and database name)

Or can you tell some other way to do what I want to do ?
Prabhakar Reddy Bokka
Ranch Hand

Joined: Jul 26, 2005
Posts: 189

You can try with the DBCP api. Hopefully it works.

DBCP Example


SCJP 5, SCWCD 5
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Getting pooled connection using DSN
 
Similar Threads
need help
jdbc-jsp
Understanding Connection Pooling - a few problems
How to use DBCP with JNDI ?
How to use JNDI to get a Pooled Connection