Skip to Main Content

Java Database Connectivity (JDBC)

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

DBCP manual configuration not working with SQL Server :S

843859May 10 2006 — edited May 10 2006
Hello,
I'm trying to utilize the DBCP connection pooling in a stand alone application (for proof of concept purpose) and trying to connect to MsSQL Server 2000. I'm getting this error


Error:[Microsoft][ODBC SQL Server Driver][SQL Server]Login failed for user '(null)'. Reason: Not associated with a trusted SQL Server connection.


My authentication mode is SQL Server and i'm sending user id and password correctly, coz i am able to connect using normal DriverManager.getConnection call when the DBCP driver is not loaded.

I'm using the code given at Apache's website. I'm trying to manual configure the PoolingDriver. Given below is the snippet of the code

public void setupDriver(String connectURI) throws Exception
    {
        //
        // First, we'll need a ObjectPool that serves as the
        // actual pool of connections.
        //
        // We'll use a GenericObjectPool instance, although
        // any ObjectPool implementation will suffice.
        //
        ObjectPool connectionPool = new GenericObjectPool(null);
 
        //
        // Next, we'll create a ConnectionFactory that the
        // pool will use to create Connections.
        // We'll use the DriverManagerConnectionFactory,
        // using the connect string passed in the command line
        // arguments.
        //
        ConnectionFactory connectionFactory = new DriverManagerConnectionFactory(connectURI,null);
 
        //
        // Now we'll create the PoolableConnectionFactory, which wraps
        // the "real" Connections created by the ConnectionFactory with
        // the classes that implement the pooling functionality.
        //
        PoolableConnectionFactory poolableConnectionFactory = new PoolableConnectionFactory(connectionFactory,connectionPool,null,null,false,true);
 
        //
        // Finally, we create the PoolingDriver itself...
        //
        Class.forName("org.apache.commons.dbcp.PoolingDriver");
        PoolingDriver driver = (PoolingDriver) DriverManager.getDriver("jdbc:apache:commons:dbcp:");
 
        String poolName = "testPool"; 
        
        //
        // ...and register our pool with it.
        //
        driver.registerPool("testPool",connectionPool);
 
        //adding the pooled connection into the pooled connection list.
        pooledConnectionList.add(connectURI);
        
        //
        // Now we can just use the connect string "jdbc:apache:commons:dbcp:testPool
        // to access our pool of Connections.
        //
    }
here is my calling code

if( !loadedDriverList.contains(configuration.getDriverClassName() ))
			{
				loadDriver( configuration.getDriverClassName() );
			}	
			
			if( !(configuration.getConnectionUrl().length() <= 0) )
			{
				setupDriver( configuration.getConnectionUrl());
				driverSetupProperly = true;
			}
			
			Connection connection = DriverManager.getConnection("jdbc:apache:commons:dbcp:testPool", "sa","mypassword" );
 
 
}
Now i'm getting the above error. What is wrong with the above code. I tried making the code simpler, i had other things going but i'm pretty sure they have nothing to do with this connection code. has any one tried running DBCP under stand alone platform, I hope DBCP does not assume that its running under Apache tomcat context or something. if this is the case then i'm gonna have to do it the JNDI way. Please i need some expert to clarify. One last thing, is format of the connection string im passing is correct?


The code i'm using is available at

[link]http://svn.apache.org/viewcvs.cgi/jakarta/commons/proper/dbcp/trunk/doc/ManualPoolingDriverExample.java?rev=155410&view=log[link]

Ali
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Jun 7 2006
Added on May 10 2006
1 comment
275 views