gpt4 book ai didi

java 与 postgresql 语句错误

转载 作者:行者123 更新时间:2023-12-01 14:04:40 25 4
gpt4 key购买 nike

我试图从数据库中获取有关已完成查询的结果,即使结果为真,数据库也总是给我“假”。

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

/************ ********/ 数据库配置

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

最佳答案

db always get me "false" even when that has trued.

来自javadoc :

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

关于java 与 postgresql 语句错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19008208/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com