Solved

SQL statement issues

Posted on 2003-11-19
4
389 Views
Last Modified: 2010-04-01
hi, i have this jsp page,

<input type="text" name="p_code" />
<input type="text" name="filterA" />
 <input type="text" name="ex_A" />

<input type="text" name="filterB" />
 <input type="text" name="ex_B" />

<input type="text" name="filterC" />
 <input type="text" name="ex_C" />

<input type="text" name="filterD" />
<input type="text" name="ex_D" />


<input type="submit" value="submit" />


and this is my DB schema,

P_code    Filter       Expired Date


And i wish to pump data into this table to make it like this,

P_code       Filter       Expired Date
A123          Filter A        12/2/2003
A123          Filter B        25/2/2003
.
.
.
.

How would be my sql statement? I only need the insert statement...

Thank You.
0
Comment
Question by:superman19
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
4 Comments
 
LVL 15

Expert Comment

by:dualsoul
ID: 9785094
i assume you get form parameters in your servlet to variables:
   pCode
    fileterA, filterB, fileterC
    ex_a, ex_b, ex_c
with request.getParameter(), like this one:
...............
    pCode=request.getParameter("p_code);
...............
and then just 3 SQL statements to update your DB:
.........................
insert into yourtable (P_code, Filter, ExpiredDate) values (pCode, filterA, ex_a)
insert into yourtable (P_code, Filter, ExpiredDate) values (pCode, filterB, ex_b)
insert into yourtable (P_code, Filter, ExpiredDate) values (pCode, filterC, ex_c)
..............................
0
 
LVL 19

Accepted Solution

by:
Kuldeepchaturvedi earned 250 total points
ID: 9786275
What dualsoul is saying will work perfectly but I would have done it like this...
<input type="text" name="p_code" />
<input type="text" name="filter" />
<input type="text" name="ex" />

<input type="text" name="filter" />
<input type="text" name="ex" />

<input type="text" name="filter" />
<input type="text" name="ex" />

<input type="text" name="filter" />
<input type="text" name="ex" />

Now in servlet
String[] filter=request.getParameterValues("filter");
String[] ex=request.getParameterValues("ex");
String p_code=request.getParameter("p_code');
for(int i=0; i<filter.length; i++)
insert into yourtable (P_code, Filter, ExpiredDate) values (p_code, filter[0], ex[0]);

This is less code and extensible to more than three inserts in the system..
Regards
0
 
LVL 3

Expert Comment

by:applekanna
ID: 9790486
Kuldeep ,
I have a doubt here , is the order of appreacnce of data on the form same as the way it appreas to the servlet
I mean if have

<input type="text" name="filter" value = "one"/>
<input type="text" name="filter" value = "two"/>

the at receiving end
filter[0] = one
filter[1] = two  ?

Thank you
0
 
LVL 14

Expert Comment

by:kennethxu
ID: 9793388
>> , is the order of appreacnce of data on the form same as the way it appreas to the servlet
I mean if have
YES!
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

A hard and fast method for reducing Active Directory Administrators members.
By reading this blog, MSPs will gain insight into how to improve communications with their clients as well as establish a more profitable business.
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…
In an interesting question (https://www.experts-exchange.com/questions/29008360/) here at Experts Exchange, a member asked how to split a single image into multiple images. The primary usage for this is to place many photographs on a flatbed scanner…

732 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question