Wrox Programmer Forums
Go Back   Wrox Programmer Forums > Java > Other Java > Java Databases
|
Java Databases Discussion specific to working with Java Databases. For other Java topics, please see related Java forums. For database discussions not specific to Java, please see the Database category.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Java Databases section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old August 31st, 2007, 06:21 AM
Registered User
 
Join Date: Aug 2007
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Default Multiple select box

Hi all,
Iam trying to insert multiple values to a database from a multiple select box. But it inserting only one value. Here iam showing my simplified jsp code. Plz help me.......

 <%
        String s13;
        String driver = "org.gjt.mm.mysql.Driver";
        Connection con=null;
        PreparedStatement pstmt=null;
        String sql="INSERT INTO comp_det(membtype,products) VALUES(?,?)";
    s13=request.getParameter("membtype");
    String[] s14=request.getParameterValues("multipleselect");
try
  {
    Class.forName(driver).newInstance();
        String url="jdbc:mysql://localhost:3306/vinikzdb";
    con=DriverManager.getConnection(url,"vinikz","vini kz");
        pstmt=con.prepareStatement(sql);
         pstmt.setString(13, s13);
         int i = 0;
         while (i < s14.length ) {
         pstmt.setString(14, s14[i] + " , " );
         i++;
         }
        pstmt.executeUpdate();

 
Old September 4th, 2007, 07:21 AM
Friend of Wrox
 
Join Date: Mar 2007
Posts: 373
Thanks: 0
Thanked 1 Time in 1 Post
Default

place the executeUpdate() method in the while() loop and try.

- Rakesh





Similar Threads
Thread Thread Starter Forum Replies Last Post
Multiple select box question cstooch Classic ASP Professional 5 December 10th, 2007 06:56 PM
Populating a multiple select box from a database ozzii Classic ASP Databases 0 February 15th, 2007 06:40 AM
Fill select box and select recordset value markd Classic ASP Databases 1 February 20th, 2006 06:41 PM
select box/List box alphabetic sort sasidhar79 Javascript How-To 3 November 10th, 2004 03:04 AM
Create an Array from a multiple select box drgreybow01 Classic ASP Basics 1 August 10th, 2003 08:51 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.