on 07-31-2014 2:50 PM
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 ...
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();
}
}
}
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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.
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.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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)
User | Count |
---|---|
89 | |
10 | |
10 | |
10 | |
7 | |
6 | |
6 | |
5 | |
4 | |
3 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.