java - How to combine two arraylists into one arraylist and pass it to procedure -
i need , assistant in combining 2 arraylists new arraylist passed procedure. once user selected certificates type list, stored in:
private list<string> selectedtypeacertificates = new arraylist<string>();
and once user selected certificates type b, stored in:
private list<string> selectedtypebcertificates = new arraylist<string>();
now in procedure need pass 2 string variables. 1 staff code , other selectedtypes both types & b.
callablestatement callablestatement = connection.preparecall("{call processcertificates(?, ?)}"); callablestatement.setint(1, staff_code); callablestatement.setstring (2, ); //i need pass selectedtypebcertificates & selectedtypeacertificates
you can add elements both lists newly created one, , use stringbuilder
build string in order pass procedure:
list<string> selectedcertificates = new arraylist<string>(); selectedcertificates.addall(selectedtypeacertificates); selectedcertificates.addall(selectedtypebcertificates); stringbuilder sb = new stringbuilder(); (string cert : selectedcertificates) { sb.append(cert); sb.append("','"); } string certificatesstring = sb.tostring(); if(!certificatesstring.isempty()) { certificatesstring = "'" + certificatesstring.substring(0, certificatesstring.lastindexof(",")) + "'"; }
the last couple of lines there remove trailing comma. of course might need change if procedure expects string in different format.
Comments
Post a Comment