简体   繁体   English

此选择语句的正确Derby SQL语法是什么?

[英]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. 我有一个名为TestDB的数据库,有一个名为USERNAME的模式,并且有一个名为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. 我遇到的问题是,在NetBeans Derby SQL中运行此查询时,我需要在select语句中使用双引号,但我显然不能在Java中使用2套双引号,因为它无法识别这是一个完整的字符串。 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. 这是我尝试运行时出现的错误消息:java.sql.SQLSyntaxErrorException:语法错误:在第1行第24列遇到“ \\'LoginTable \\'”。

Use can escape double quotes inside a string using backslash. Use可以使用反斜杠在字符串内转义双引号。

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. 只是不确定Derby DB是否是其中之一。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM