Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Using JAVA Create an Update method in the UserDB class that updates a User objec

ID: 3890252 • Letter: U

Question

Using JAVA

Create an Update method in the UserDB class that updates a User object.

In the servlet code we created last week that allows the user to reset their password, utilize the UserDb update method to save the changes to the db.

last week assignment was to:

Create a User JavaBean. The User bean should have all the attributes collected from the new customer form. Also give it a username and password property.

retrieve the user from the session and change the password to the password entered on the reset form.

Save the User object in session scope.

Redirect the user to the account_activity page.

Explanation / Answer

here is code to show how you can update database record in java:

Java updateDB code:

import java.sql.Connection;

import java.sql.DriverManager;

import java.sql.SQLException;

import java.sql.Statement;

public class UserDB

{  

//to update user password through user mail id

//just pass user email id and new password

public void updatePass(String password,String UserEmail)

Connection con = null;

Statement stmt = null;

try {

Class.forName("oracle.jdbc.driver.OracleDriver");

con = DriverManager.

getConnection("jdbc:oracle:thin:@<hostname>:<port num>:<DB name>" //your host name and port and name for example "jdbc:oracle:thin:@localhost:1521:MrGreen";

,"user","password");//here username and password

stmt = con.createStatement();

String query = "update table password set password="+password+" where userEmail= "+userEmail;//db update query

tmt.executeUpdate(query);

} catch (ClassNotFoundException e) {

// TODO Auto-generated catch block

e.printStackTrace();

} catch (SQLException e) {

// TODO Auto-generated catch block

e.printStackTrace();

}

finally

{

try

{/*-----to close connection----*/

if(stmt != null) stmt.close();

if(con != null) con.close();

} catch(Exception ex){}

}

}

}

I hope this solves your problem

Comment if you have any problem in above code

And please give it a thumbs up if it solved your problem :)

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote