我正在使用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)
答案 0 :(得分:2)
问题是您的查询有语法错误。
在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);