This week's book giveaway is in the OO, Patterns, UML and Refactoring forum. We're giving away four copies of Refactoring for Software Design Smells: Managing Technical Debt and have Girish Suryanarayana, Ganesh Samarthyam & Tushar Sharma on-line! See this thread for details.
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 ?