This week's book giveaway is in the Agile and Other Processes forum.
We're giving away four copies of The Little Book of Impediments (e-book only) and have Tom Perry on-line!
See this thread for details.
Win a copy of The Little Book of Impediments (e-book only) this week in the Agile and Other Processes forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

DBCP -- connection string for SQL Server

 
eric zhao
Greenhorn
Posts: 20
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Folks:

Anyone has experience using DBCP with SQL Server? What is the connection String for SQL Server? I am using following for oracle, but couldn't find any documentation for SQL Server: (replace # with :, : was displayed as icons for some reason)

jdbc#oracle#thin#userid/password@server#port#Databasename

Thanks.

[ August 24, 2005: Message edited by: eric zhao ]
[ August 24, 2005: Message edited by: eric zhao ]
 
Tom Blough
Ranch Hand
Posts: 263
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If you are using Microsoft's type 4 JDBC Driver then it's:



Otherwise, it depends on your driver.

Cheers,
[ August 24, 2005: Message edited by: Tom Blough ]
 
eric zhao
Greenhorn
Posts: 20
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks, Tom. But with DBCP, when dealing with oracle or mysql, I have userid and password passed in explicitly in the connection string. I don't know how to do the same with SQL Server.

Any suggestions? Do I have to change my wrapper code for DBCP for SQL Server? Below is the code I wrote to wrap DBCP (pooled driver) used for my projects, it works if the userid and password are in connectionURL. How can I pass the userid and password outside the connectionURL?

ObjectPool connectionPool = new GenericObjectPool(null, maxActive, GenericObjectPool.WHEN_EXHAUSTED_BLOCK, 5000);

ConnectionFactory connectionFactory = new DriverManagerConnectionFactory(connectURI, null);

PoolableConnectionFactory poolableConnectionFactory = new
PoolableConnectionFactory(connectionFactory, connectionPool, null, null, false, true);
Class.forName("org.apache.commons.dbcp.PoolingDriver");
PoolingDriver driver = (PoolingDriver) DriverManager.getDriver(
"jdbc:apache:commons bcp:");
driver.registerPool(poolname, connectionPool);


Many thanks.

Eric
[ August 29, 2005: Message edited by: eric zhao ]
 
Tom Blough
Ranch Hand
Posts: 263
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Eric, just use the connectonFactory constructor that take the user name and password as parameters:



Cheers,
 
eric zhao
Greenhorn
Posts: 20
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Tom, thank you very much for your help.

Do you happen to know if there is some website having good documentation for DBCP? DBCP's own website has very limited examples and how-tos.

Have a great day.
 
eric zhao
Greenhorn
Posts: 20
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Tom,

Still more problems. Even if I pass in the userid and password with the constructor you mentioned, I still get the following error messge:
[Microsoft][SQLServer 2000 Driver for JDBC][SQLServer]Login failed for user '(null)'. Reason: Not associated with a trusted SQL Server connection.

Any ideas? I have googled this error and haven't found any pointers.

thanks.

Eric
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic