• 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

Getting pooled connection using DSN

 
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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 ?
 
Ranch Hand
Posts: 198
Oracle Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You can try with the DBCP api. Hopefully it works.

DBCP Example
reply
    Bookmark Topic Watch Topic
  • New Topic