java - 另一个类中的 SQL 更新
问题描述
感谢您帮助我解决我的问题。因此,我尝试使用名为 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 在该行中没有给我任何错误。
推荐阅读
- flutter - Flutter:使用在多个屏幕中使用的提供程序更新特定屏幕
- reactjs - useState 设置方法不会立即反映更改
- performance - Enumerable.SequenceEqual(list1, list2) 相对于 list1.All(list2.Contains) 有什么优缺点?
- python - 如何在 django 的字符串中生成此输出?
- artifactory - 单个用户的幻影神器
- tsql - 将 T-SQL INNER JOIN 语句转换为 DAX
- javascript - 如何使用 JavaScript(或其他解决方案)将相同的标签添加到 Qualtrics 调查中的多个滑块?
- python - pandas系列中如何使用多重条件,选择少数并取移动平均
- vue.js - 添加显示/隐藏超时元素 UI
- javascript - 检测 YouTube 视频何时结束使用 Youtube Player API 无法正常工作