how to add conditions at run time with prepare statement using jdbc in java
in search when the parameter are too many i want to use condition at runtime
dim sqlstmt as new StringBuilder
sqlstmt.add("SELECT * FROM Products")
sqlstmt.add(" WHERE 1=1")
''// From now on you don't have to worry if you must
''// append AND or WHERE because you know the WHERE is there
if (ProductCategoryID <> 0){
sqlstmt.append(" AND ProductCategoryID = ?")
}
if (MinimunPrice > 0){
sqlstmt.AppendFormat(" AND Price >= ?")
}
how can i using prepare statement in this case , what is you experience? and when my query is like this:
with data as ( SELECT QUESTION_ID, count(*) COUNTT, dense_rank() over (order by count(*) desc) dense_rank "
FROM EXAM_STD_QUESTIONS esq
inner join EXAM e
where e.teacherId=?
group by QUESTION_ID )
select q.id,q.difficulty_degree ,q.page_number,q.text,q.teacher_guide, q.description,q.picture,q.time,t.fullname,s.name Subject,p.name Part, d.COUNTT,d.QUESTION_ID from data d "
inner join question q on q.id=d.QUESTION_ID "
inner join teacher t on t.id= q.teacher_id "
inner join subject s on s.id = q.subject_id "
inner join part p on p.id=q.part_id "
where d.dense_rank=? and q.LESSON_ID=? and q.REFRENCE_ID=? and q.STATUS=1 ORDER BY DBMS_RANDOM.VALUE FETCH NEXT ? ROWS ONLY
in this query we have to where and ... how can i add condition in this case at run time and handle prepare statement?