gurpalrattu
gurpalrattu

Reputation: 221

What is the proper Derby SQL syntax for this select statement?

String SQL = "SELECT * from USERNAME."LoginTable" ";

I have a database named TestDB, I have a schema named USERNAME and I have a table called LoginTable.

The problem I'm having is that I need to use the double quotes in the select statement when I run this query in NetBeans Derby SQL, but I clearly can't use 2 sets of double quotes in Java because it won't recognize that it's a complete String. What is the proper way to write this so I won't have this problem come up again in the future?

Here is the error message thats coming up when I try to run: java.sql.SQLSyntaxErrorException: Syntax error: Encountered "\'LoginTable\'" at line 1, column 24.

Upvotes: 0

Views: 872

Answers (1)

clinux
clinux

Reputation: 3074

Use can escape double quotes inside a string using backslash.

Eg.

String myString = "My String contains \"Double Quotes\"";

And if you need a backslash in a string, then escape it with a backslash.

Eg.

String oneBackslash = "\\";

So yours now becomes

String SQL = "SELECT * from USERNAME.\"LoginTable\" ";

A lot of database engines I've used allow the use of single quotes too. Just not sure if Derby DB is one of them.

Upvotes: 1

Related Questions