cancel
Showing results for 
Search instead for 
Did you mean: 

Start Database command "AS" with number = exception

Former Member
0 Kudos

Hello,

When I use the command START DATABASE in Java like this:

String query = "START DATABASE '" + databasePath + "' AS " + databaseName;

statement.execute(query);

But if the databaseName is a number then I get this error:

31-07-14 15:44:33 [ERROR] TechLogger -  -> com.sybase.jdbc3.jdbc.SybSQLException: ASA Error -131: Syntax error near '3051' on line 1

  at com.sybase.jdbc3.tds.Tds.a(Unknown Source)

  at com.sybase.jdbc3.tds.Tds.nextResult(Unknown Source)

  at com.sybase.jdbc3.jdbc.ResultGetter.nextResult(Unknown Source)

  at com.sybase.jdbc3.jdbc.SybStatement.nextResult(Unknown Source)

  at com.sybase.jdbc3.jdbc.SybStatement.nextResult(Unknown Source)

  at com.sybase.jdbc3.jdbc.SybStatement.executeLoop(Unknown Source)

  at com.sybase.jdbc3.jdbc.SybStatement.execute(Unknown Source)

  at com.sybase.jdbc3.jdbc.SybStatement.execute(Unknown Source)

  at eu.adm.solutions.topaccount2irisxtract.util.SqlUtils.startDatabase(SqlUtils.java:123)

  at eu.adm.solutions.topaccount2irisxtract.util.SqlUtils.getCustomers(SqlUtils.java:95)

  at eu.adm.solutions.topaccount2irisxtract.process.ProcessFiles.processFiles(ProcessFiles.java:38)

  at eu.adm.solutions.topaccount2irisxtract.process.Task.run(Task.java:51)

  at java.util.TimerThread.mainLoop(Unknown Source)

  at java.util.TimerThread.run(Unknown Source)

This is a sample query:  START DATABASE 'w:\TOP\DATA\3051\3051.DB' AS 3051

When I run this query inside the Interactive SQL it runs without a problem ...

I've also tried quotes and double quotes around the databaseName, no succes ...

Accepted Solutions (1)

Accepted Solutions (1)

JasonHinsperger
Advisor
Advisor
0 Kudos

The following code sample works for me. I see the database started correctly in the server window and I can connect to it from dbisql.


import java.io.*;

import java.sql.*;

import java.util.*;

class T

{

    public static void main (String args[]) throws IOException    {

  Connection    con = null;

       con = connect();

       if( con == null ) {

          return; // exception should already have been reported

       }

       try {

          con.createStatement().execute( "START DATABASE 'test.db' AS \"1234\"" );

          con.close();

          System.out.println( "Disconnected" );

       } catch (SQLException sqe) {

          printExceptions(sqe);

       }

    }

  

   private static Connection connect()    {

       String    conn_str, url;

       Connection  connection;

       conn_str = "jdbc:sqlanywhere:uid=DBA;pwd=sql";

       try {

          connection = DriverManager.getConnection( conn_str );

       }  catch( Exception e ) {

          System.err.println( "Error! Could not connect" );

          System.err.println( e.getMessage() );

          printExceptions( (SQLException)e );

          connection = null;

       }

       return connection;

    }

    static private void printExceptions(SQLException sqe)    {

        while (sqe != null)        {

              System.out.println("Unexpected exception : " +

            "SqlState: " + sqe.getSQLState()  +

            " " + sqe.toString() +

            ", ErrorCode: " + sqe.getErrorCode());

               System.out.println( "======================================" );

                      sqe = sqe.getNextException();

         }

    }

}

Former Member
0 Kudos

Hi Jason,

Thank you for your answer. Your code also works for me, and the only difference that I see is the jdbc.sqlanywhere connection string instead of the jdbc:sybase I use, so that's probably it.

I've found that I don't need the AS because my databasefilename and databasename are the same, so removing that works for me.

Answers (1)

Answers (1)

reimer_pods
Participant
0 Kudos

The docs say that the database name is an identifier. If the database name consists only of numbers, it has to be enclosed in double quotes.

DocCommentXchange Start Database

DocCommentXchange Identifier

Former Member
0 Kudos

Hi Reimer,

I tried that already, even for the path also:

String query = "START DATABASE \"" + databasePath + "\" AS \"" + databaseName + "\"";

START DATABASE "w:\TOP\DATA\3051\3051.DB" AS "3051"

Still the same error ...

31-07-14 16:49:11 [ERROR] TechLogger -  -> com.sybase.jdbc3.jdbc.SybSQLException: ASA Error -131: Syntax error near '3051' on line 1

  at com.sybase.jdbc3.tds.Tds.a(Unknown Source)

  at com.sybase.jdbc3.tds.Tds.nextResult(Unknown Source)

  at com.sybase.jdbc3.jdbc.ResultGetter.nextResult(Unknown Source)

  at com.sybase.jdbc3.jdbc.SybStatement.nextResult(Unknown Source)

  at com.sybase.jdbc3.jdbc.SybStatement.nextResult(Unknown Source)

  at com.sybase.jdbc3.jdbc.SybStatement.executeLoop(Unknown Source)

  at com.sybase.jdbc3.jdbc.SybStatement.execute(Unknown Source)

  at com.sybase.jdbc3.jdbc.SybStatement.execute(Unknown Source)

  at eu.adm.solutions.topaccount2irisxtract.util.SqlUtils.startDatabase(SqlUtils.java:128)

  at eu.adm.solutions.topaccount2irisxtract.util.SqlUtils.getCustomers(SqlUtils.java:95)

  at eu.adm.solutions.topaccount2irisxtract.process.ProcessFiles.processFiles(ProcessFiles.java:38)

  at eu.adm.solutions.topaccount2irisxtract.process.Task.run(Task.java:51)

  at java.util.TimerThread.mainLoop(Unknown Source)

  at java.util.TimerThread.run(Unknown Source)