Sql 我准备的陈述有什么问题?
SQL语句:Sql 我准备的陈述有什么问题?,sql,oracle,prepared-statement,Sql,Oracle,Prepared Statement,SQL语句: SELECT * FROM ( SELECT rownum rid ,condata.* FROM ( SELECT max(ODP_CTT.NUM_CTT_ID) conid ,ODP_CTT.VC2_BUS_CTT_ID AS ecpid ,ODP_CTT.vc2_title AS title ,ODP_CTT.vc2_briefly AS description ,EC_ECP_INFO.vc2_price AS opri ,e
SELECT * FROM (
SELECT rownum rid ,condata.*
FROM (
SELECT max(ODP_CTT.NUM_CTT_ID) conid ,ODP_CTT.VC2_BUS_CTT_ID AS ecpid ,ODP_CTT.vc2_title AS title ,ODP_CTT.vc2_briefly AS description ,EC_ECP_INFO.vc2_price AS opri ,ec_ecp_info.vc2_discount AS npri ,max(ODP_CTT.vc2_dft_icon) AS iurl ,to_char(ec_ecp_info.dat_update, 'yyyymmddhhmiss') AS upt
FROM ODP_CTT ,ec_ecp_info
where odp_ctt.num_status = 3
and (
lower(vc2_title) LIKE lower('%?%')
or lower(ODP_CTT.vc2_briefly) LIKE lower('%?%')
)
AND ec_ecp_info.vc2_ecp_id = odp_ctt.VC2_BUS_CTT_ID
GROUP BY ODP_CTT.VC2_BUS_CTT_ID ,ODP_CTT.vc2_title ,ODP_CTT.vc2_briefly ,EC_ECP_INFO.vc2_price ,ec_ecp_info.vc2_discount ,to_char(ec_ecp_info.dat_update, 'yyyymmddhhmiss')
) condata
order by to_number (upt) desc
)
我设定:
stmt.setString(1, keyword_f);
stmt.setString(2, keyword_f);
我得到:
java.sql.SQLException:oracle.jdbc.driver.DatabaseError.throwSqlException(DatabaseError.java:112)处的列索引无效
我认为你不能把?
放在一个字符串中。您可能需要这样做:
lower(vc2_title) LIKE lower(?)
or lower(ODP_CTT.vc2_briefly) LIKE lower(?)
然后在Java中:
stmt.setString(1, "%" + keyword_f + "%");
stmt.setString(2, "%" + keyword_f + "%");
@user452187我更新了我的答案。基本相同,只是没有
**
stmt.setString(1, "%" + keyword_f + "%");
stmt.setString(2, "%" + keyword_f + "%");