This week's book giveaway is in the Kotlin forum.
We're giving away four copies of Kotlin in Action and have Dmitry Jemerov & Svetlana Isakova on-line!
See this thread for details.
Win a copy of Kotlin in Action this week in the Kotlin forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

update data in a loop  RSS feed

 
gilberto silva
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello, im the beginners and have a problem in part of my website. For instance, the array is passed from the previous page and the items in the array is not fixable. In the array, it contain some names which need to be changed their age to 40 in database. This is my code, however, it's not work.


<%
String[] array = {"charles","betty","simon","tony","ivy"};

Class.forName("com.mysql.jdbc.Driver").newInstance();
Connect connection = DriverManager.getConnection(, "jdbc:mysql://mysql2.000webhost.com/a3932573_product","root", "");
String sql = "update user set user_age = 40 where name_of_user = ? ";
PreparedStatement ps = conn.prepareStatement(sql);


for(int i = 0 ; i<array.length ; i++){

String name = array[i];
ps.setString(1, name);
ps.executeUpdate();

}
%>
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 66188
151
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Why is this code in a JSP?
 
gilberto silva
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It is just a part of my jsp page. The previous page is asking user to select the name who should be change to 40. then it will pass all the value to this page and i use an array contain all of it. Therefore i said the array is not fixed. Then I want to change the age with specific name(the name in the array) to 40 in the database by pressing a button called confirm. And the code on the previous is the database part in a loop.
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 66188
151
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Your first step is to move all Java code out of JSPs and into Java classes where it belongs. Putting Java code into JSP pages is a bad practice from before 2002 when JSP2 was introduced.

Your second step is to acquaint yourself with modern JSP development using the JSTL (JSP Standard Tag Library) and EL (Expression Language).

I recommend newcomers to JSP read
  • The Secret Life of JSPs
  • The Front Man



  •  
    Don't get me started about those stupid light bulbs.
    • Post Reply Bookmark Topic Watch Topic
    • New Topic
    Boost this thread!