User Name Password Register
DaniWeb IT Discussion Community
All
What is DaniWeb IT Discussion Community?
You're currently browsing the JSP section within the Web Development category of DaniWeb, a massive community of 423,884 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 4,235 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our JSP advertiser: Lunarpages JSP Web Hosting
Views: 7877 | Replies: 5
Reply
Join Date: Mar 2006
Posts: 20
Reputation: muthumari is an unknown quantity at this point 
Rep Power: 3
Solved Threads: 0
muthumari muthumari is offline Offline
Newbie Poster

inserting multiple selection from checkbox in to one column

  #1  
Mar 30th, 2006
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
AddThis Social Bookmark Button
Reply With Quote  
Join Date: Feb 2006
Posts: 1,456
Reputation: masijade is just really nice masijade is just really nice masijade is just really nice masijade is just really nice masijade is just really nice 
Rep Power: 9
Solved Threads: 129
masijade's Avatar
masijade masijade is online now Online
Nearly a Posting Virtuoso

Re: inserting multiple selection from checkbox in to one column

  #2  
Mar 30th, 2006
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
Reply With Quote  
Join Date: Mar 2006
Posts: 20
Reputation: muthumari is an unknown quantity at this point 
Rep Power: 3
Solved Threads: 0
muthumari muthumari is offline Offline
Newbie Poster

Help Re: inserting multiple selection from checkbox in to one column

  #3  
Mar 30th, 2006
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).
Reply With Quote  
Join Date: Feb 2006
Posts: 1,456
Reputation: masijade is just really nice masijade is just really nice masijade is just really nice masijade is just really nice masijade is just really nice 
Rep Power: 9
Solved Threads: 129
masijade's Avatar
masijade masijade is online now Online
Nearly a Posting Virtuoso

Re: inserting multiple selection from checkbox in to one column

  #4  
Mar 30th, 2006
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.
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
Reply With Quote  
Join Date: Mar 2006
Posts: 20
Reputation: muthumari is an unknown quantity at this point 
Rep Power: 3
Solved Threads: 0
muthumari muthumari is offline Offline
Newbie Poster

Re: inserting multiple selection from checkbox in to one column

  #5  
Mar 30th, 2006
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
Reply With Quote  
Join Date: Feb 2006
Posts: 1,456
Reputation: masijade is just really nice masijade is just really nice masijade is just really nice masijade is just really nice masijade is just really nice 
Rep Power: 9
Solved Threads: 129
masijade's Avatar
masijade masijade is online now Online
Nearly a Posting Virtuoso

Re: inserting multiple selection from checkbox in to one column

  #6  
Mar 30th, 2006
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();
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
Reply With Quote  
Reply

Only community members can participate in forum threads. You must register or log in to contribute.

DaniWeb JSP Marketplace
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)

 

Thread Tools Display Modes

Similar Threads
Other Threads in the JSP Forum

All times are GMT -4. The time now is 4:46 am.
Forum system based on vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC