cancel
Showing results for 
Search instead for 
Did you mean: 

CONNECT TO statement in Java

Former Member
0 Kudos

Hello,

When I try to use the connect statement in Java like this:

//connect to database
query = "CONNECT TO 'TOPADMINSA9' DATABASE 'ARCUS' USER 'dba' IDENTIFIED BY 'stef'";
//query = "CONNECT TO '" + config.getDatabase() + "' DATABASE '" + databaseName + "' USER '" + config.getUser() + "' IDENTIFIED BY '" + config.getPassword() + "'";
logger.info(query);
statement.executeQuery(query);

I get this error:

16-07-14 10:47:52 [ERROR] TechLogger -  -> com.sybase.jdbc3.jdbc.SybSQLException: ASA Error -131: Syntax error near 'CONNECT' on line 1

But when I execute the same command in my SQL Anywhere Interactive SQL the query works fine.

Any idea what I'm doing wrong?

Accepted Solutions (1)

Accepted Solutions (1)

JasonHinsperger
Advisor
Advisor
0 Kudos

CONNECT is a DBISQL specific command, not a general database statement.  To connect using JDBC you use the getConnection() method.  You can find an example in the SQL Anywhere documentation here:

http://dcx.sybase.com/index.html#sa160/en/dbprogramming/connecting-establishing-jdbc.html

Former Member
0 Kudos

Thank you Jason,

I hadn't thought about that ... I use that way to connect to my main database ( where I get the path for other databases), and to open those I used the START DATABASE command, so I assumed I had to connect also through SQL.

Thank you very much.

Answers (0)