java与postgresql错误的声明

时间:2013-09-25 14:50:23

标签: java postgresql connection database-connection

我试图从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;
}

2 个答案:

答案 0 :(得分:1)

  

db总是让我“假”,即使这已经过了。

来自javadoc

如果第一个结果是execute对象,则ResultSet方法返回 true ; false,如果是更新次数,或者没有结果

答案 1 :(得分:0)

您可以尝试使用executeUpate。在执行INSERT,UPDATE,DELETE时更清楚。它返回此查询影响的行数。