Skip to Content
avatar image
Former Member

CONNECT TO statement in Java

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?

Add comment
10|10000 characters needed characters exceeded

  • Get RSS Feed

1 Answer

  • Best Answer
    Jul 16, 2014 at 12:00 PM

    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

    Add comment
    10|10000 characters needed characters exceeded

    • Former Member

      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.