Results 1 to 4 of 4
  1. #1
    Join Date
    Aug 2012
    Posts
    3

    Unanswered: SQLSyntaxErrorException with single quoted string inside a string

    Hello -

    I need to have a single-quoted string inside a quoted string for the sql string used by Statement. It compiles fine but at runtime throws a syntax exception. I have tried quoting the internal single quotes but there was no change. Can someone please tell me how to do this correctly?
    Thanks.

    the sqlplus command: select sys_context('USERENV','SID') as SID from dual;

    my java code:
    Statement stmt = conn.createStatement();
    sql = "select sys_context(\'USERENV\',\'SID\') as SID from dual;";
    System.out.println("DbWorker::getConnSid: EXECUTE STATEMENT - "+ sql);
    stmt.execute(sql);

    throws: java.sql.SQLSyntaxErrorException: ORA-00911:

    Thanks a lot.

  2. #2
    Join Date
    Aug 2012
    Posts
    3
    the answer is to remove the semicolon from the select string:
    from: sql = "select sys_context(\'USERENV\',\'SID\') as SID from dual;";
    to: sql = "select sys_context(\'USERENV\',\'SID\') as SID from dual";

  3. #3
    Join Date
    Sep 2012
    Posts
    1
    hiii,
    my name is Abhijit,
    i hv built one desktop application now i want to knw wat is aquery to filter records from datatables

  4. #4
    Join Date
    Aug 2012
    Posts
    3
    Hello Abidba -
    The query to issue to retrieve a SID is given here for this original question. That does not filter records from a database. For that, someone else will need to direct you. From my experience, I learned how to do that by studying Java's JDBC.
    Good-luck.

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •