1

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?

skaffman
  • 398,947
  • 96
  • 818
  • 769
Eric Milas
  • 1,807
  • 2
  • 18
  • 29

2 Answers2

4

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();
Loxley
  • 1,781
  • 17
  • 20
0

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

Chochos
  • 5,155
  • 22
  • 27