쿼리 매개 변수의 값을 기반으로 동적 쿼리를 작성하고 싶습니다. 조건에 따라 검색어 매개 변수의 값이나하지, 문자열 쿼리가 추가 된 것이 있다면 나는, 그 결과이 같은이자바의 쿼리 매개 변수 값을 기반으로하는 동적 쿼리
String strSQL = "select tb_r_orderdata.customerid,\n" +
"REPLACE(REPLACE(REPLACE(LEFT(finishtime,10),'-',''),':',''),'T','') as paydate,\n" +
"tb_r_orderdata.amount,\n" +
"tb_r_orderdata.acquirementid,\n" +
"tb_r_orderdata.tracking_ref,\n" +
"tb_m_biller_product.billerdesc, \n" +
"tb_m_biller_product.productdesc, \n" +
"tb_r_orderdata.hpno, \n" +
"tb_r_orderdata.email, \n" +
"tb_r_orderdata.rc, \n" +
"tb_r_orderdata.rcdesc, \n" +
"tb_r_orderdata.additionaldata_pay \n" +
"from tb_r_orderdata JOIN tb_m_biller_product ON tb_r_orderdata.productid=tb_m_biller_product.productid AND tb_r_orderdata.billerid=tb_m_biller_product.billerid \n" +
"where status='SUCCESS';";
같은 문자열 쿼리가 있습니다.
는 여기에 내가 시험 그것을 가지고 내 조건
String newstrSQL = strSQL;
PreparedStatement pst=null;
if (period != null) {
newstrSQL = strSQL + "and REPLACE(REPLACE(REPLACE(LEFT(finishtime,10),'-',''),':',''),'T','')>=?";
}
if (tanggal != null) {
newstrSQL = strSQL + "and REPLACE(REPLACE(REPLACE(LEFT(finishtime,10),'-',''),':',''),'T','')<=?";
}
if (billerid != null) {
newstrSQL = strSQL + "and tb_m_biller_product.billerid = ?";
}
if (productid != null) {
newstrSQL = strSQL + "and tb_m_biller_product.productid = ?";
}
if (custom != null) {
newstrSQL = strSQL + "and" + searchby + " = ?";
}
pst = con.prepareStatement(newstrSQL);
pst.setString(1, period);
pst.setString(2, tanggal);
pst.setString(3, billerid);
pst.setString(4, productid);
pst.setString(5, custom);
rs = pst.executeQuery();
,하지만 결과는 항상 0과 구문 오류가 없습니다. 고마워, 나쁜 영어에 대해 죄송합니다.
'period'가'null'이라면 여전히'pst.setString (1, period);'을 호출하고 싶습니까? – alfasin