This week's book giveaway is in the General Computing forum.
We're giving away four copies of Arduino in Action and have Martin Evans, Joshua Noble, and Jordan Hochenbaum on-line!
See this thread for details.
The moose likes JDBC and the fly likes DBCP -- connection string for SQL Server Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login


JavaRanch » Java Forums » Databases » JDBC
Reply Bookmark "DBCP -- connection string for SQL Server" Watch "DBCP -- connection string for SQL Server" New topic
Author

DBCP -- connection string for SQL Server

eric zhao
Greenhorn

Joined: Feb 26, 2003
Posts: 20
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

Joined: Jul 31, 2003
Posts: 263
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 ]

Tom Blough<br /> <blockquote><font size="1" face="Verdana, Arial">quote:</font><hr>Cum catapultae proscriptae erunt tum soli proscripti catapultas habebunt.<hr></blockquote>
eric zhao
Greenhorn

Joined: Feb 26, 2003
Posts: 20
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

Joined: Jul 31, 2003
Posts: 263
Eric, just use the connectonFactory constructor that take the user name and password as parameters:



Cheers,
eric zhao
Greenhorn

Joined: Feb 26, 2003
Posts: 20
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

Joined: Feb 26, 2003
Posts: 20
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
 
I agree. Here's the link: http://ej-technologies/jprofiler - if it wasn't for jprofiler, we would need to run our stuff on 16 servers instead of 3.
 
subject: DBCP -- connection string for SQL Server
 
Similar Threads
Servlet Context and database connection
using jsp to copg files from a directory
Apache Commons DBCP connection object problem
Portlet Configuration
What are the principles of OOA/D?