DB insertion problem
//checkboxes
req.getParameter("srvis1");
req.getParameter("srvis2");
req.getParameter("srvis3");
req.getParameter("srvis4");
req.getParameter("srvis5");
//Oracle DB Table is:
co_id, co_services;
Question: user may check one, two or all of them but how can i insert them at a time in one colum
thanks in advance
Suppose you will insert srvis1 to srvis5 to co_services column.
-- co_services is defined as CHAR(5) --
Your code may look something like this
// Data conversion method
public string convertNullToSpace(String args) {
// I'm not sure if the unchecked item will return null or whitespace from .getParameter. Pls verify this.
if (args == null) {
return " "; // return whitespace
}
return args;
}
// your database insertion method
public ....... {
....
// this is the easiest but less efficient way
String coServices = convertNullToSpace(req.getParameter("srvis1")) + convertNullToSpace(req.getParameter("srvis2")) + ......;
/* after the above line, you should have a 5-char length data e.g. YYYYY or Y Y Y, depends on which and how many checkboxes were checked */
PrepareStatement pstmt = ......("INSERT INTO T_XXX VALUES (?, ?);
pstmt.setString(2, coServices);
....
String[] product=req.getParameterValues("prod");
if (product != null)
{
for (i=0;i<product.length;++i){
product=product;
}
} //Works OK
String[] prod_detail=req.getParameter("prod_detail");//Error
if (prod_detail != null)
{
for (i=0;i<prod_detail.length;++i){
prod_detail=prod_detail;
}
}
String[] prod_detail=(String[])req.getParameter("prod_detail");//Error
if (prod_detail != null)
{
for (i=0;i<prod_detail.length;++i){
prod_detail=prod_detail;
}
}
can you plz correct it. thanks>
Then I suggest you do a little coding. I have given you the needed code change to continue with the way you have it coded already. I don't know what you want to do with the String array once you have it, so I can't help you with that. Simply replace the first snippet with the second snippet and drive on.