java.sql.SQLException : ORA-00933: SQL command not properly ended Error with LIKE Sql Query

标签 java oracle jdbc

我正在使用 jdbc。我在以下准备好的语句中遇到异常

  PreparedStatement pstmt=con.prepareStatement("select * from customer where INITIALIZED=1 && FILE_NAME LIKE ?");
  //filename is string
  pstmt.setString(1, "%" + filename + "%");
  rs=pstmt.executeQuery();

我收到以下错误

  016-06-01 18:59:55 ERROR DatabaseUtils:276 - java.sql.SQLException: ORA-00933: SQL command not properly ended

Exception in thread "main" java.lang.NullPointerException
at pe.entel.DatabaseInsertionandRetrieving.LocalDatabaseTransactImpl.retrievewithfilename(LocalDatabaseTransactImpl.java:279)
at pe.entel.DatabaseInsertionandRetrieving.LocalDatabaseTransactImpl.main(LocalDatabaseTransactImpl.java:287)

最佳答案

问题是您的查询有语法错误。 在 SQL 中,您需要使用 AND 而不是 &&,如下所示:

// Introduced sql only for a better reading
String sql = "select * from customer where INITIALIZED=1 AND FILE_NAME LIKE ?";
PreparedStatement pstmt = con.prepareStatement(sql);

关于java.sql.SQLException : ORA-00933: SQL command not properly ended Error with LIKE Sql Query,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37570302/

相关文章:

Java将字节[]转换为图像

java - 为什么 List<valueObject> 在 Hibernate 中给出错误?

c# - 我如何知道哪个参数导致 OracleCommand Insert 出现 FormatException ("Input string was not in a correct format")?

sql - ORA-19279 : XPTY0004 - XQuery dynamic type mismatch: expected singleton sequence

Java执行多条SQL语句并写入excel

java - java中oracle查询性能

java - 如何从Java类的外部将对象添加到类中的对象数组中

java - System.out.printLn() 如何接受整数?

java - 使用 Java 连接到 Amazon RDS 实例时如何解决 ORA-12514

java - Jaybird SocketInputStream.socketread0 线程阻塞