I have tried to getting result from db about has done query,db always get me "false" even when that has trued.
oldPassword = DBConfig.MD5(oldPassword); //thase are me own classes
newPassword = DBConfig.MD5(newPassword);
String updatePassword = "UPDATE login " + "SET password='"
+ newPassword + "'" + " WHERE password='" + oldPassword
+ "' and employee_id=" + userId + " ;";
Connection con = DBConfig.dbConfigure();
Statement statement = con.createStatement();
boolean success = statement.execute(updatePassword);
LOGGER.info(success);
DBManager.close(con, statement, null); //I'm closing connectin,statmant and result set if that has
/********************/ DBConfig
public static final String USER_NAME = "postgres";
public static final String PASSWORD = "password";
public static final String DB_NAME="jdbc:postgresql://localhost/myTask";
public static final String DB_DRIVER = "org.postgresql.Driver";
public static Connection dbConfigure() throws ClassNotFoundException,
SQLException {
String userName = USER_NAME;
String dbPassword = PASSWORD;
String dbName = DB_NAME;
String dbDriver = DB_DRIVER;
Class.forName(dbDriver);
Connection con = DriverManager.getConnection(dbName, userName,
dbPassword);
return con;
}
passwordas part of the query, instead retrieve the user password and do a match in server side i.e. in Java, then do a clean update. Also, usePreparedStatements instead of plainStatements to avoid SQL Injection.executeUpdatemethod instead of plainexecute.