简体   繁体   English

使用apache Derby的WHERE子句上的SQL语法错误

[英]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_NAMEFROM加入。 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.

相关问题 使用 Netbeans IDE / Derby 的 WHERE 子句上的 SQL 语法错误 - SQL syntax error on WHERE clause using Netbeans IDE / Derby Apache Derby - 语法错误:在第8行第2列遇到“;” - Apache Derby - Syntax error: Encountered “;” at line 8, column 2 derby中的sql错误-错误42X01:语法错误:遇到“ WHERE” - sql Error in derby - ERROR 42X01: Syntax error: Encountered “WHERE” 在 Java Apache Derby 数据库中获取 java.sql.SQLSyntaxErrorException: Syntax error: Encountered "(" at line 1, column 53? - In Java Apache Derby Database getting java.sql.SQLSyntaxErrorException: Syntax error: Encountered "(" at line 1, column 53? 多列,IN 子句 Apache Derby - Multiple columns in, IN clause Apache Derby 在具有JFrame形式的NetBeans derby中将SELECT语句与WHERE子句一起使用 - Using SELECT statement with a WHERE clause in Netbeans derby with JFrame forms 使用JDBC在Apache Derby数据库中执行批量插入时,出现语法错误:DERBY-PROPERTIES。 我究竟做错了什么? - When preforming bulk insert in Apache Derby database using JDBC, I get a Syntax error: DERBY-PROPERTIES. What am I doing wrong? 将WHERE NOT EXISTS与伪表一起使用不能在Apache Derby数据库上运行 - Using WHERE NOT EXISTS with dummy table not working on Apache Derby Database 对Apache Derby使用LDAP - Using LDAP for Apache Derby 使用Apache derby的异常 - Exception using apache derby
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM