JAVA - MySQL an ArrayList -
i have query mysql
string sqlsearch = "select * item"
and method arraylist
public static arraylist<string> checkno() throws sqlexception { arraylist<string> no= new arraylist<string>(); dbmanager db = new dbmanager(); db.connect(); string sql = "select * category id = " + iduser + " "; statement stmt = db.connect().createstatement(); resultset rs = stmt.executequery(sql); while (rs.next()) { no.add(rs.getstring("namecategory")); } db.disconnect(); return no; }
and specific user category in arraylist, how pass category sqlsearch???
select * item category ???? data arraylist
any idea?
you loop through arraylist
items , build string
use in where
clause this
string incondition = ""; boolean first = true; arraylist<string> categories = checkno(); for(string cat : categories){ if(first){ first = false; } else { incondition += ","; } incondition += cat; } string sqlsearch = "select * item category in (" + incondition + ")";
Comments
Post a Comment