mysql - Insert Into 添加双记录 MySQL 语句
问题描述
在 IntelliJ 中,我试图向 MySQL 表添加新记录,但是,当我启动服务器(Tomcat 9.0.141)时,它会添加双记录。当我刷新浏览器时,它只添加一次,当我启动服务器(Tomcat)时,它添加两次。我到处都在寻找答案,甚至在FB上的群里,也没有人知道该说什么。请帮忙。这是我的整个 servlet:
@WebServlet(value = "/sqlu")
public class MySQLServletUpdate extends HttpServlet {
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
response.setContentType("text/plain; charset=utf-8");
try{
Driver driver = new com.mysql.cj.jdbc.Driver();
DriverManager.registerDriver(driver);
Connection connection = DriverManager.getConnection("jdbc:mysql://localhost:3306/AppJEE?useSSL=false&characterEncoding=utf8&useJDBCCompianttimezoneShift=true&useLegacyDatetimecode=false&serverTimezone=UTC", "root", "password");
PreparedStatement pstmt = connection.prepareStatement("INSERT INTO user VALUES (null, ?, ?, ?)");
pstmt.setString(1, "Mark");
pstmt.setString(2, "Marks");
pstmt.setString(3, "Mar");
if (pstmt.executeUpdate() > 0) {
response.getWriter().println("Record added");
}
} catch (SQLException e) {
e.printStackTrace();
}
}
}
这是我在 phpMyAdmin 中查看表格时出现的一些错误:
Warning in ./libraries/sql.lib.php#613
count(): Parameter must be an array or an object that implements Countable
Backtrace
./libraries/sql.lib.php#2128: PMA_isRememberSortingOrder(array)
./libraries/sql.lib.php#2079: PMA_executeQueryAndGetQueryResponse(
array,
boolean true,
string 'AppJEE',
string 'uzytkownik',
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
string '',
string './themes/pmahomme/img/',
NULL,
NULL,
NULL,
string 'SELECT * FROM `uzytkownik`',
NULL,
NULL,
)
./sql.php#221: PMA_executeQueryAndSendQueryResponse(
array,
boolean true,
string 'AppJEE',
string 'uzytkownik',
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
string '',
string './themes/pmahomme/img/',
NULL,
NULL,
NULL,
string 'SELECT * FROM `uzytkownik`',
NULL,
NULL,
)
./index.php#53: include(./sql.php)
这是我桌子上的一个视图1
这是我表2上的另一个视图
解决方案
我通过设置 Tomcat 服务器仅运行而不立即加载页面来解决我的问题。当Tomcat运行时,我手动进入浏览器和加载页面,然后它只添加一次记录。
推荐阅读
- javascript - NodeJS - 如何从 blob 下载?
- python - PCA 显示低解释方差分数
- typo3 - 在 TYPO3 中制作联系表格时在哪里可以找到表格选项卡
- javascript - 如何“正确”检测使用 Javascript 的 WEBP 图像的 mime 类型
- windows - 在本地网络上查看 html 文件
- python - 如何找到“FileNotFoundError”的解决方案
- angular - `breadcrumb` - 累积,而不是在移出页面时重置
- excel-formula - 如何根据另一列的数据在另一列中添加规则
- ubuntu - 静态 html 文件上的 Nginx 404
- google-sheets - 当 F7 和 I7 给定时间时,如果 A 和 B 之间的时间显示 X