Unanswered: SQLSyntaxErrorException with single quoted string inside a string
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?
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);
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";
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.