简体   繁体   中英

Getting a Connection with DBCP via the Sybase Jconnect JDBC driver

I am trying to get a Connection in the following code and I keep getting an SQLException with the message "Login failed" and with the details "Specified database not found".

Connection con = null;    
BasicDataSource dataSource = new BasicDataSource();
dataSource.setDriverClassName("com.sybase.jdbc.SybDriver");
dataSource.setUsername("username");
dataSource.setPassword("password");
dataSource.setDefaultAutoCommit(true);
dataSource.setDefaultTransactionIsolation(Connection.TRANSACTION_READ_UNCOMMITTED);
dataSource.setMaxActive(1);
dataSource.setMaxIdle(1);
dataSource.addConnectionProperty("databaseName", dbName);
dataSource.addConnectionProperty("servicename", dbName);
dataSource.setUrl("jdbc:sybase:Tds:127.0.0.1:2638");
con = dataSource.getConnection();

I have also tried putting the dbName in url and setting it as a property in the url.

dataSource.setUrl("jdbc:sybase:Tds:127.0.0.1:2638/dbName");
dataSource.setUrl("jdbc:sybase:Tds:127.0.0.1:2638?SERVICENAME=dbName");

None of it works. It seems to be seeing the server just fine as the error changes if the url is wrong to just "Connection refused" message.

Any ideas?

You could use SybDataSource, the following is enough:

import com.sybase.jdbc4.jdbc.SybDataSource;

SybDataSource dataSource = new SybDataSource();
dataSource.setUser("username");
dataSource.setPassword("password");
dataSource.setServerName("hostname");
dataSource.setPortNumber(5000);
con = dataSource.getConnection();

I think the URL should be jdbc:sybase:Tds:127.0.0.1:2638?ServiceName=dbName (perhaps it's case-sensitive)

http://www.razorsql.com/docs/help_sybase.html

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM