• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Devaka Cooray
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Jeanne Boyarsky
  • Tim Cooke
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Tim Moores
  • Mikalai Zaikin
  • Carey Brown
Bartenders:

Update more than one rows through one Submit/Update Button

 
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi....
Can any one help me out on this ...
i have 10 different data in 10 different textboxes/combo boxes..... now i want to "update" the database with the data that is there in the fields through ONE update button .....
So its like i have a unique id field ... as IdNumber .... and for these idnumber i'm entering values in the text box as well as combo boxes....
if there would be only one text box called date and one combo box named class then my update statement would be ...
(Update <tablename> set date = '"+date+"',class ='"+class+"' where idnumber = '"+idNumber+"')
but now the problem is that i have more than 1 data for both the date textbox and class combo box ... so how would i go bout the updating of the records ......
Example
IDnumber :123,124,125,126
TextboxDate : 2003-10-15 ,2003-20-10 ,2003-09-03 .
ClassCombobox abc, def,ghi
So in the database it would be updating the coloum date and class for the IDNUMBER 123 where the date feild would be updated with the value 2003-10-15 and the class field will be updated with the value abc ... then for the IDNUMBER 124 the date field will be updated with the value 2003-20-10 and the class field will be updated with the value "def" and so on ...
so that means that for each idnumber i have to update the database date feild and combo box .... how would i do that .....
plz keep in mind that all this has to be done ... on ONE sumbit button/update button which calls another jsp ......
Retreiving the values is not a problem ... updating the values corresponding to the idnumber is a problem ....
Plz if any one else can help .... i would be very thankful
If possible ..... please try and include a sample code
Thanxsssss
:roll:
 
Author
Posts: 399
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hi..
Can you possible loop the update query...an idea quite off the top of my mind....there could be some other possiblities too...
What I mean to say is..
May be you can store the values in an array, & run the update query in a loop in your bean.
hth
MB
 
Ranch Hand
Posts: 645
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,
C if following approch hepls u

String sDates[]=request.getParameterValues("date");//date is name of ur text box
String sClass[]=request.getParameterValues("class");
String sIds=request.getParameterValues("id");
for(int i=0;i<=ids.length;++i)
{
(Update <tablename> set date = '"+sDates[i]+"',class ='"+sClass[i]+"' where idnumber = '"+sIds[i]+"')
}
cheers
Praful
 
Mehak Daani
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi praful....
I tried the code that u had posted.. but now it gives the error :
Incompatible type for =. Can't convert java.lang.String to
java.lang.String[].

......
 
Ranch Hand
Posts: 100
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
can u post your code that we can understand better???
Thanks
Amit
 
Mehak Daani
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Below is my full code ..... my "prioset.jsp" is calling this file. ....
all the names that u see in the while loop like txtname+i,prio+i,exp+i..are coming from the previous jsp where the name of the textbox and combo box keeps changing ........
so the txtname+i goes into the tg_date ,then the prio+i goes into the priority and the exp+i goes into the expert string ....and in my databse corresponding to each call id i have a tg_date,priority and expert coloum ....
i have removed the String[] and now i'm using vectors to store the values through the add element ..... now if i write
for(cnt=0;cnt<v_callids.size();cnt++)
{
a_call = v_callids.elementAt(cnt).toString();
a_exp= v_experts.elementAt(cnt).toString();
a_pri = v_pri.elementAt(cnt).toString();
a_date = targetdate.elementAt(cnt).toString();

}
now if i have supposing 4 records .... so for the above code .... the a_call get the 4 id's but the a_exp,a_pri,and a_date get only ONE value ..... that means that the loop iterates 4 times for the a_call but only onece for the other three ....
The reason what came into my mind was that in my for loop the vector whose size i'm taking is v_callid's and the a_call is also storing the value v_callids.elementAt(cnt) ...... so may be that's y it's get all 4 values .... coz i couldn't notice any other reason as to y it should iterate 4 times only for "a_call"....???
If any one can find any other reason do let me know ......
Now how can i iterate through all the vectors one after another .... means ..... that i want to write a loop such that it should iterate and get the first value of the callid,tg_date,pri,expert ...then update ...then iterated through the second value ... and so on ....!!!
I have tried
String date[] = request.getParameter("txtname" + i);
But it gives a conversion error
Incompatible type for =. Can't convert java.lang.String to
java.lang.String[].
Any body has ideas to solve my problem ....!!! :roll:
my code is below .... awaiting for replies .... and yeah how do i convert a string to String[]......??? is there any built in function for it ...???

<%
Class.forName("com.mysql.jdbc.Driver");
Connection conn=DriverManager.getConnection("jdbc:mysql://localhost:3306/it_support","root","");
int i = 0;
int n =0;
int ex =0;
int p = 0;
int cnt = 0;
int c =0;

String tgdate = new String();
String tg_date = new String();
String tempdate = new String();
String temp_expert = new String();
String experts = new String();
String tempexp = new String();
String pri = new String();
String temp_pri = new String();
String priority = new String();
String callid = new String();
String temp_callid = new String();
String call_id = new String();
String a_call = new STring();
String a_exp = new STring();
String a_pri = new STring();
String a_date = new STring();


Vector targetdate = new Vector();
Vector v_expert = new Vector();
Vector v_pri = new Vector();
Vector v_callid = new Vector();
Vector v_callids = new Vector();
Statement stmt1 = conn.createStatement();
Statement uprecord = conn.createStatement();
ResultSet gtcount = stmt1.executeQuery("Select * from complaints where status =0");
while(gtcount.next())
{
i = i+1;
tgdate = request.getParameter("txtname" + i) ;
targetdate.addElement(tgdate);
temp_expert = request.getParameter("exp" + i);
v_expert.addElement(temp_expert);
pri = request.getParameter("prio" + i);
v_pri.addElement(pri);
call_id = gtcount.getString("callid");
v_callid.addElement(call_id);
}

tempdate = targetdate.toString();
n = tempdate.length()-1;
tg_date = tempdate.substring(1,n);
/*-------------------------------*/
tempexp = v_expert.toString();
ex = tempexp.length()-1;
experts = tempexp.substring(1,ex);
/*-------------------------------*/
temp_pri = v_pri.toString();
p = temp_pri.length()-1;
priority = temp_pri.substring(1,p);
/*-------------------------------*/
temp_callid = v_callid.toString();
c = temp_callid.length()-1;
callid = temp_callid.substring(1,c);
/*-------------------------------*/
v_callids.addElement(callid);
out.println("The values" + ca);
out.println("The string values" + tg_date);
out.println("Total no: of Records Retreived " + i);
out.println("The string experts" + experts);
out.println("The string priority" + priority);
out.println("-------------------------------");
out.println("The string callid " + callid);
out.println("-------------------------------");

for(cnt=0;cnt<v_callids.size();cnt++)
{
out.println("Entering in loop");
a_call = v_callids.elementAt(cnt).toString();
a_date = targetdate.elementAt(cntd).toString();
a_exp = v_expert.elementAt(cnte).toString();
a_pri = v_pri.elementAt(cntp).toString();
out.println("calls" + a_call);
out.println("-------------------------------");
out.println("a_date" + a_date);
out.println("-------------------------------");
out.println("exp" + a_exp);
out.println("-------------------------------");
out.println("pri" + a_pri);
}

%>
<br><br>
<input type="submit" name="Submit" value="Submit">
<input type="reset" value="Reset">
</form>
</body>
</html>
 
Praful Thakare
Ranch Hand
Posts: 645
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
sweety,
It's not
String date[] = request.getParameter("txtname" + i);
it is
String date[] = request.getParameterValues("txtname" + i);
Praful
 
Sheriff
Posts: 67735
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Welcome to the Ranch Sweety!
You'll find this forum a great place to seek help on JSP pages, and there aren't many rules you'll have to worry about, but one is that proper names are required. Please take a look at the JavaRanch Naming Policy and change your display name to match it.
Thanks!
bear
JSP Forum Bartender
 
Mehak Daani
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hey
thanks to all for helping me out .... now my jsp is working fine....!!!
bye.....!!!

 
Every plan is a little cooler if you have a blimp. And a tiny ad.
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic