感谢您帮助我解决问题。 因此,我尝试使用名为 Functions 的类中的方法插入 SQL 更新,主程序不会给出任何错误,并且每当我使用该函数时,它在刷新后不会更改 SQL 表中的任何内容。
这是我在 Functions 类中的 updateSQL 方法:
public static void updateSQL(String sql, String updatenames[])
{
Connection connected = null;
PreparedStatement prepared = null;
connected = connexionmysql.connexionDB();
try
{
prepared = connected.prepareStatement(sql);
for(int i = 1; i < updatenames.length+1 ; i++) {
prepared.setString(i, updatenames[i-1]);
}
prepared.execute();
}
catch (SQLException e)
{
e.printStackTrace();
}
}
这是我在主类中调用此函数的方式:
String datan[] = { inputPASS, type1, inputEMAIL, inputNAME };
Functions.updateSQL("UPDATE users SET userPASS = ? ,userTYPE = ? ,userEMAIL = ? WHERE userNAME = ? ", datan);
最佳答案
我确实解决了这个问题。我编写的函数按预期工作,但问题出在我调用方法的方式上。
我没有以静态方式调用该函数,而是以“通常”方式调用它,这样 Eclipse 就不会在该行中给出任何错误。
关于java - 另一个类中的 SQL 更新,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/61545713/