| | |
inserting multiple selection from checkbox in to one column
Please support our JSP advertiser: PostgreSQL or MySQL? Compare and contrast the two most popular open source databases
![]() |
With a prepared statement and multiple executes.
Java Programmer and Sun Systems Administrator
----------------------------------------------
Debugging is twice as hard as writing the code in the first place. Therefore, if you write the code as cleverly as possible, you are, by definition, not smart enough to debug it.
--Brian Kernighan
----------------------------------------------
Debugging is twice as hard as writing the code in the first place. Therefore, if you write the code as cleverly as possible, you are, by definition, not smart enough to debug it.
--Brian Kernighan
•
•
Join Date: Mar 2006
Posts: 20
Reputation:
Solved Threads: 0
•
•
•
•
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).
No What I meant was using the JDBC prepared statement. here an example:
of course replacing checkbox, table, and field with the real things.
JSP Syntax (Toggle Plain Text)
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.
Java Programmer and Sun Systems Administrator
----------------------------------------------
Debugging is twice as hard as writing the code in the first place. Therefore, if you write the code as cleverly as possible, you are, by definition, not smart enough to debug it.
--Brian Kernighan
----------------------------------------------
Debugging is twice as hard as writing the code in the first place. Therefore, if you write the code as cleverly as possible, you are, by definition, not smart enough to debug it.
--Brian Kernighan
•
•
Join Date: Mar 2006
Posts: 20
Reputation:
Solved Threads: 0
•
•
•
•
Originally Posted by masijade
No What I meant was using the JDBC prepared statement. here an example:
JSP Syntax (Toggle Plain Text)
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
Are you using jdk 1.5 or an earlier version. If you are not using 1.5 then the following lines
must be changed:
to:
must be changed:
JSP Syntax (Toggle Plain Text)
for (String val : vals) { pStmt.setString(1, val); pStmt.execute();
to:
JSP Syntax (Toggle Plain Text)
for (int i = 0; i < vals.length; i++) { pStmt.setString(1, vals[i]); pStmt.execute();
Java Programmer and Sun Systems Administrator
----------------------------------------------
Debugging is twice as hard as writing the code in the first place. Therefore, if you write the code as cleverly as possible, you are, by definition, not smart enough to debug it.
--Brian Kernighan
----------------------------------------------
Debugging is twice as hard as writing the code in the first place. Therefore, if you write the code as cleverly as possible, you are, by definition, not smart enough to debug it.
--Brian Kernighan
-1
#8 Oct 15th, 2009
Learn to see in another's calamity the ills which you should avoid.
Publilius Syrus
(~100 BC)
LJC - London Java Community, Graduate & Undergraduate Software Development Community, JAVAWUG (Java Web User Group), The London Android Group
Publilius Syrus
(~100 BC)
LJC - London Java Community, Graduate & Undergraduate Software Development Community, JAVAWUG (Java Web User Group), The London Android Group
![]() |
Similar Threads
- Store multiple selection from pagination info into single array (PHP)
- How to store multiple selection? (VB.NET)
- How do I populate multiple column list box? (Visual Basic 4 / 5 / 6)
- Adding a checkbox column dynamically (C#)
Other Threads in the JSP Forum
- Previous Thread: can some one help me
- Next Thread: problem in importing package
| Thread Tools | Search this Thread |
apache array backbutton combobox comma connection csv database development directorystructure dropdownlist dynamicpagetitles eclipse frames glassfish ie8 imagetodatabse imageupload integer internet java javaee javascript jsf jsp jsppagetitles levels mvc2 mvcmodel2 mysql netbeans network parameters passing ping printinserverinsteadofclient read redirect request.getparameter response seperated servlet servletdopost()readxml sessions software sql ssl state_saving_method stocks sun tomcat tutorial update values video web write






