나는 db에 대한 결과를 얻으려고했는데, db는 항상 "false"를 얻었다.java with postgresql 실수로 문장이
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;
}
IMO 검색어의 일부로 'password'를 사용하지 말고 대신 사용자 비밀번호를 검색하고 서버 측 즉 Java에서 일치 항목을 검색 한 다음 새로 업데이트합니다. 또한, SQL Injection을 피하기 위해'Statement's 대신'PreparedStatement'를 사용하십시오. –
또한'execute' 대신'executeUpdate' 메소드를 사용하십시오. –
답변 해 주셔서 감사합니다. – Unknown