Win a copy of Testing JavaScript Applications this week in the HTML Pages with CSS and JavaScript forum!
  • 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Bear Bibeault
  • Ron McLeod
  • Jeanne Boyarsky
  • Paul Clapham
Sheriffs:
  • Tim Cooke
  • Liutauras Vilda
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • fred rosenberger
  • salvin francis
Bartenders:
  • Piet Souris
  • Frits Walraven
  • Carey Brown

Getting pooled connection using DSN

 
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
  • 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
  • Quote
  • Report post to moderator
You can try with the DBCP api. Hopefully it works.

DBCP Example
 
Don't get me started about those stupid light bulbs.
    Bookmark Topic Watch Topic
  • New Topic