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

[378 byte] By [ZafarAliKhana] at [2007-10-3 4:16:12]
# 1
I think you need to append the results from .getParameter yourself before inserting to the database column.If you define db column as CHAR(5), you may want to convert any unchecked item into '_' (space) or 'N' before appending it.:D
TikkyChaia at 2007-7-14 22:17:44 > top of Java-index,Database Connectivity,Java Database Connectivity (JDBC)...
# 2
TikkyChai thanks for your reply but can u please write an example for me?
ZafarAliKhana at 2007-7-14 22:17:44 > top of Java-index,Database Connectivity,Java Database Connectivity (JDBC)...
# 3

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);

....

TikkyChaia at 2007-7-14 22:17:44 > top of Java-index,Database Connectivity,Java Database Connectivity (JDBC)...
# 4

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>

ZafarAliKhana at 2007-7-14 22:17:44 > top of Java-index,Database Connectivity,Java Database Connectivity (JDBC)...
# 5
As I said in your other postgetParameter("param");returns a String not an array of Strings.For an array of Strings usegetParameterValues("param");read the API Doc for ServletRequest.
masijade.a at 2007-7-14 22:17:44 > top of Java-index,Database Connectivity,Java Database Connectivity (JDBC)...
# 6
this is decided but I am requesting a solution via coding
ZafarAliKhana at 2007-7-14 22:17:44 > top of Java-index,Database Connectivity,Java Database Connectivity (JDBC)...
# 7

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.

masijade.a at 2007-7-14 22:17:44 > top of Java-index,Database Connectivity,Java Database Connectivity (JDBC)...
# 8
1. I am trying to get multiple text input2. saving into array or whatever u suggest the method3. inserting the saved multiple input text fields into DB
ZafarAliKhana at 2007-7-14 22:17:44 > top of Java-index,Database Connectivity,Java Database Connectivity (JDBC)...