0

我试图从 db 中获取关于已完成查询的结果,db 总是让我“假”,即使那是真的。

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;
}
4

2 回答 2

1

db 总是让我“假”,即使那是真的。

javadoc

如果第一个结果是对象,则该execute方法返回true ;如果是更新计数或没有结果,则为 falseResultSet

于 2013-09-25T14:55:57.093 回答
0

您可以尝试使用executeUpate。当您执行 INSERT、UPDATE、DELETE 时,情况会更加清晰。它返回受此查询影响的行数。

于 2013-09-25T14:59:37.673 回答