DaniWeb IT Discussion Community

DaniWeb IT Discussion Community (http://www.daniweb.com/forums/index.php)
-   JSP (http://www.daniweb.com/forums/forum24.html)
-   -   inserting multiple selection from checkbox in to one column (http://www.daniweb.com/forums/thread42241.html)

muthumari Mar 30th, 2006 2:09 am
inserting multiple selection from checkbox in to one column
 
Hi,


Hoe to insert multiple selection from checkbox(from jsp) in to one column of the table(sql server database ).


Anyone can you help me?

Thanx

masijade Mar 30th, 2006 2:38 am
Re: inserting multiple selection from checkbox in to one column
 
With a prepared statement and multiple executes.

muthumari Mar 30th, 2006 3:29 am
Re: inserting multiple selection from checkbox in to one column
 
Quote:

Originally Posted by masijade
With a prepared statement and multiple executes.




Hi,
Thanx for your reply . I know, how to retreive the checkbox value(using prepared statement with request.getParameteVales("checkboxname")).



But, It will return an array of values.
I don't know about how to insert this array of values into single column of the table(sqlserver database).

masijade Mar 30th, 2006 4:42 am
Re: inserting multiple selection from checkbox in to one column
 
No What I meant was using the JDBC prepared statement. here an example:

String[] vals = request.getParameterValues("checkbox");
try {
  PreparedStatement pStmt = conn.prepareStatement("Insert into table (field) values (?)");
  for (String val : vals) {
    pStmt.setString(1, val);
    pStmt.execute();
  }
} catch .....

of course replacing checkbox, table, and field with the real things.

muthumari Mar 30th, 2006 8:18 am
Re: inserting multiple selection from checkbox in to one column
 
Quote:

Originally Posted by masijade
No What I meant was using the JDBC prepared statement. here an example:

String[] vals = request.getParameterValues("checkbox");
try {
  PreparedStatement pStmt = conn.prepareStatement("Insert into table (field) values (?)");
  for (String val : vals) {
    pStmt.setString(1, val);
    pStmt.execute();
  }
} catch .....

of course replacing checkbox, table, and field with the real things.



Hi i have one error in this line:

pStmt.setString(1, val);


The error is ; expected.
I haven't any idea about this

Can you help me

masijade Mar 30th, 2006 8:53 am
Re: inserting multiple selection from checkbox in to one column
 
Are you using jdk 1.5 or an earlier version. If you are not using 1.5 then the following lines
must be changed:

  for (String val : vals) {
    pStmt.setString(1, val);
    pStmt.execute();

to:

  for (int i = 0; i < vals.length; i++) {
    pStmt.setString(1, vals[i]);
    pStmt.execute();

alokranjan.java Oct 15th, 2009 1:17 pm
multiple checkbox & textfield insert in Oracle9i using Jsp

peter_budo Oct 15th, 2009 2:32 pm
Quote:

Originally Posted by alokranjan.java (Post 1015596)
multiple checkbox & textfield insert in Oracle9i using Jsp

It is bad enough that you reopened old thread you did not even provided proper description of whatever you up to. Do you mind to correct your mistake?


All times are GMT -4. The time now is 11:23 pm.

Forum system based on vBulletin Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
©2003 - 2009 DaniWeb® LLC