Reputation: 1847
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?
Upvotes: 1
Views: 7060
Reputation: 1781
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();
Upvotes: 4
Reputation: 5159
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
Upvotes: 0