【问题标题】:java.sql.SQLSyntaxErrorException: ORA-00936: missing expression even though nothing is missingjava.sql.SQLSyntaxErrorException: ORA-00936: 缺少表达式,即使什么都没有
【发布时间】:2020-03-19 14:20:17
【问题描述】:

我在以下语句中收到 java.sql.SQLSyntaxErrorException: ORA-00936: missing expression。我在任何地方都看不到任何拼写错误或多余的逗号。为什么我会收到此错误?

rs = st.executeQuery("select password from logininfo where username = " + uname);

其中 uname 是一个字符串变量。

【问题讨论】:

  • 学会使用参数来传递值,你将永远不会再遇到这个特殊问题。
  • uname 周围缺少单引号。但正如 Gordon Linoff 所说,您确实希望使用参数而不是连接查询字符串。
  • @GMB uname 是一个字符串变量
  • rs = st.executeQuery("select password from logininfo where username = '" + uname + "'");

标签: sql database oracle oracle11g


【解决方案1】:

您收到错误可能是因为 uname 的值为空(零长度)字符串,因此让您的数据库服务器尝试运行查询...

select password from logininfo where username =

...这是...嗯...在= 运算符之后缺少一个表达式。

正如评论者已经指出的那样,使用参数(在某些数据库服务器方面也称为“绑定变量”),即执行语句...

select password from logininfo where username = ?

... 绑定 uname 变量的值到查询的第一个参数。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-05-18
    • 2017-08-31
    相关资源
    最近更新 更多