2013-09-25 2 views
0

나는 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; 
} 
+1

IMO 검색어의 일부로 'password'를 사용하지 말고 대신 사용자 비밀번호를 검색하고 서버 측 즉 Java에서 일치 항목을 검색 한 다음 새로 업데이트합니다. 또한, SQL Injection을 피하기 위해'Statement's 대신'PreparedStatement'를 사용하십시오. –

+0

또한'execute' 대신'executeUpdate' 메소드를 사용하십시오. –

+0

답변 해 주셔서 감사합니다. – Unknown

답변

1

db 항상 나에게 "fa lse "라고 말했습니다. javadoc에서

:

첫 번째 결과가 ResultSet 객체 인 경우 execute 방법은 사실을 반환 업데이트 카운트가이거나 결과가 0301이면 false

0

executeUpate을 사용해 볼 수 있습니다. INSERT, UPDATE, DELETE를 할 때 훨씬 더 명확합니다. 이 쿼리에 의해 영향을받은 행 수를 반환합니다.