简体   繁体   English

在Sql查询中获取语法错误

[英]Getting syntax error in a Sql query

Hello everyone i am trying to compare a user input id with a db id but when i execute the query i get syntax error what am i doing wrong? 大家好,我正在尝试将用户输入ID与数据库ID进行比较,但是执行查询时出现语法错误,我在做什么错呢?

 sql = "SELECT individual.id " 
                + "FROM individual"
                + "WHERE individual.id = ? ";
       PreparedStatement pst = con.prepareStatement(sql);
       pst.setInt(1, input);

    while(rs.next()){
        int Iid = rs.getInt("id");
        System.out.println(Iid);
    }

Error message 错误信息

Exception in thread "main" com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '.id = ?' at line 1
    at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
    at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
    at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
    at java.lang.reflect.Constructor.newInstance(Constructor.java:408)
    at com.mysql.jdbc.Util.handleNewInstance(Util.java:411)
    at com.mysql.jdbc.Util.getInstance(Util.java:386)
    at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:1053)
    at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:4120)
    at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:4052)
    at com.mysql.jdbc.MysqlIO.sendCommand(MysqlIO.java:2503)
    at com.mysql.jdbc.MysqlIO.sqlQueryDirect(MysqlIO.java:2664)
    at com.mysql.jdbc.ConnectionImpl.execSQL(ConnectionImpl.java:2788)
    at com.mysql.jdbc.ConnectionImpl.execSQL(ConnectionImpl.java:2738)
    at com.mysql.jdbc.StatementImpl.executeQuery(StatementImpl.java:1617)
+ "FROM individual" + "WHERE individ

Will be resolved to 将解决

  FROM individualWHERE individ...

Add spaces to your string and you should be fine 在字符串中添加空格,就可以了

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

相关问题 在JDBC中的SQL查询中获取语法错误 - Getting Syntax error in SQL query in JDBC Hibernate 查询语言:为我的查询获取 SQL 语法错误 - Hibernate Query Language: Getting a SQL Syntax Error for my Query 获取Java mysql SQL语法错误,但我的查询似乎正常 - Getting Java mysql SQL Syntax error but my query seems normal 此查询中的 sql 语法错误是什么? - whats the sql syntax error in this query? 更新查询的SQL语法错误 - SQL Syntax error for update query Spring JPA @Query - 尝试对多个 SQL ZDBC11CAABD5BDA99F77E6FBE 使用 1 个参数; 收到有关 SQL 语法的错误消息 - Spring JPA @Query - Trying to use 1 Param for multiple SQL arguments; getting error message about SQL Syntax 我在netbeans中收到42000 sql语法错误,但是相同的查询字符串在mysql控制台中工作正常 - I'm getting a 42000 sql syntax error in netbeans but the same query string works fine in mysql console I am getting a Sql Syntax error while performing update query in java( java.sql.sqlsyntaxerrorexception you have an error in your sql syntax) - I am getting a Sql Syntax error while performing update query in java( java.sql.sqlsyntaxerrorexception you have an error in your sql syntax) 获取SQL语法错误异常,不确定为什么吗? - Getting a SQL Syntax Error Exception, Not sure why? 获取条件 ADDDATE 函数的 SQL 语法错误 - Getting SQL syntax error for criteria ADDDATE function
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM