Solved

SQL statement issues

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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Suggested Solutions

In this article, I will show you HOW TO: Suppress Configuration Issues and Warnings Alert displayed in Summary status for ESXi 6.5 after enabling SSH or ESXi Shell.
Performance in games development is paramount: every microsecond counts to be able to do everything in less than 33ms (aiming at 16ms). C# foreach statement is one of the worst performance killers, and here I explain why.
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…
This video gives you a great overview about bandwidth monitoring with SNMP and WMI with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're looking for how to monitor bandwidth using netflow or packet s…

743 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

Need Help in Real-Time?

Connect with top rated Experts

14 Experts available now in Live!

Get 1:1 Help Now