Solved

SQL statement issues

Posted on 2003-11-19
4
383 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
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

Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
netstat -a in AIX unix 8 44
Clear browser cache on site login, is it possible? 3 27
lessBy10  challenge 15 95
Market Place not working in Eclipse Luna 2 113
In this article we will learn how to backup a VMware farm using Nakivo Backup & Replication. In this tutorial we will install the software on a Windows 2012 R2 Server.
Does your audience prefer people in photos or no people? How can you best highlight what you’re selling? What are your competitors doing, and what can you do that is different and unique from them?  Continue reading to learn how to make your images …
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …

831 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