我试图从数据库中获取有关已完成查询的结果,即使结果为真,数据库也总是给我“假”。
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/