我想根据siteid(integer)
中的refrenceno
,oldrefrenceno
和account(table)
进行搜索,但我的查询仅搜索refrencno(varchar(15))
和oldrefrenceno(varchar(50))
。当用户输入siteid
搜索数据时,它不显示任何内容。
Statement pst=null;
pst=ccn.createStatement();
String a=txt_search.getText();
String sql = "";
try {
int s = Integer.parseInt(siteid.getText());
sql ="select * from account WHERE siteid ="+s+" refrenceno='"+a+"' or oldrefrenceno='"+a+"' ";
}catch (Exception ex){
sql ="select * from account WHERE refrenceno='"+a+"' or oldrefrenceno='"+a+"' ";
}
ResultSet rs=pst.executeQuery(sql);
答案 0 :(得分:0)
如果您想基于三个字段进行搜索,那么您的查询应该是
sql ="select * from account WHERE siteid ="+s+" AND refrenceno='"+a+"' AND oldrefrenceno='"+a+"' ";