开发者

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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜