[英]SQL syntax error on WHERE clause using apache Derby
For the following SQL select statement ; 对于以下SQL select语句; -
-
resultSet = statement.executeQuery("SELECT SS100.ORDERS.ORDER_ID, SS100.ORDERS.ORDER_NUMBER," +" SS100.ORDERS.PERSON_ID, SS100.PERSON.FIRST_NAME"+
"FROM PERSON, ORDERS " +
"WHERE SS100.PERSON.PERSON_ID = SS100.ORDERS.PERSON_ID " );
I'm getting a syntax error on the WHERE keyword - dump as follows :- 我在WHERE关键字上遇到语法错误 - 转储如下: -
java.sql.SQLSyntaxErrorException: Syntax error: Encountered "WHERE" at line 1, column 126.
at org.apache.derby.impl.jdbc.SQLExceptionFactory40.getSQLException(Unknown Source)
at org.apache.derby.impl.jdbc.Util.generateCsSQLException(Unknown Source)
at org.apache.derby.impl.jdbc.TransactionResourceImpl.wrapInSQLException(Unknown Source)
at org.apache.derby.impl.jdbc.TransactionResourceImpl.handleException(Unknown Source)
at org.apache.derby.impl.jdbc.EmbedConnection.handleException(Unknown Source)
at org.apache.derby.impl.jdbc.ConnectionChild.handleException(Unknown Source)
at org.apache.derby.impl.jdbc.EmbedStatement.execute(Unknown Source)
at org.apache.derby.impl.jdbc.EmbedStatement.executeQuery(Unknown Source)
at Database.orderQuery(Database.java:146)
at MainApp.main(MainApp.java:19)
Caused by: java.sql.SQLException: Syntax error: Encountered "WHERE" at line 1, column 126.
at org.apache.derby.impl.jdbc.SQLExceptionFactory.getSQLException(Unknown Source)
at org.apache.derby.impl.jdbc.SQLExceptionFactory40.wrapArgsForTransportAcrossDRDA(Unknown Source)... 10 more
I've tried playing around with the alias statement, but then get an error on the '.' 我尝试过使用alias语句,但是然后在'。'上出错了。 dot operator.
点运算符。 I'm obviously doing something fundamentally wrong but I can't see it at the moment, can anyone help?
我显然做了一些根本错误的事情,但我现在看不到它,有人可以帮忙吗?
Look here: 看这里:
resultSet = statement.executeQuery("SELECT ..." +... + " SS100.ORDERS.PERSON_ID, SS100.PERSON.FIRST_NAME"+
"FROM PERSON, ORDERS " +
There's no space between "SS100.PERSON.FIRST_NAME"
and "FROM"
. "SS100.PERSON.FIRST_NAME"
和"FROM"
之间没有空格。
This can be easily solved by always starting your parts with an space: 通过始终用空间启动零件可以轻松解决这个问题:
resultSet = statement.executeQuery("SELECT ..." +... + " SS100.ORDERS.PERSON_ID, SS100.PERSON.FIRST_NAME"+
" FROM PERSON, ORDERS " +
" WHERE ..."
This concatenation of strings will turn into 字符串的这种串联将变成
"SELECT SS100.ORDERS.ORDER_ID, SS100.ORDERS.ORDER_NUMBER," +" SS100.ORDERS.PERSON_ID, SS100.PERSON.FIRST_NAME"+
"FROM PERSON, ORDERS " + "WHERE SS100.PERSON.PERSON_ID = SS100.ORDERS.PERSON_ID " “FROM PERSON,ORDERS”+“WHERE SS100.PERSON.PERSON_ID = SS100.ORDERS.PERSON_ID”
SELECT SS100.ORDERS.ORDER_ID, SS100.ORDERS.ORDER_NUMBER, SS100.ORDERS.PERSON_ID,
SS100.PERSON.FIRST_NAMEFROM PERSON, ORDERS WHERE SS100.PERSON.PERSON_ID =
SS100.ORDERS.PERSON_ID
The issue is where FIRST_NAME
and FROM
join. 问题在于
FIRST_NAME
和FROM
加入。 Add a space after FIRST_NAME
and the sql should run fine. 在
FIRST_NAME
之后添加一个空格,sql运行正常。
However, you should really be asking yourself why you are doing this. 但是,你应该问自己为什么要这样做。 If you know the values to concatenate, why not have one string to start with.
如果您知道要连接的值,为什么不能开始使用一个字符串。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.