1. 程式人生 > >JDBC 模糊查詢 傳參

JDBC 模糊查詢 傳參

寫dao的時候碰到模糊查詢的傳參,無法識別引號下的問號

1)可以利用拼接變數的方式

String sql = "select domin_id , domin_name from dmn_domin where domin_code like '"+domin_code +"%'"+" and state=? order by domin_id";

2)利用傳參函式

String sql = "select domin_id , domin_name from dmn_domin where domin_code like ? and state=? order by domin_id";

PreparedStatment stat = con.prepareStatement(sql);

stat.setString(1,"?%");