首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Insert Into add double record MySQL语句

Insert Into add double record MySQL语句
EN

Stack Overflow用户
提问于 2019-01-25 15:37:15
回答 1查看 40关注 0票数 0

在IntelliJ中,我试图向MySQL表添加新记录,但是,当我启动服务器(Tomcat9.0.141)时,它添加了双倍记录。当我刷新浏览器时,它只添加了一次,当我启动服务器(Tomcat)时,它添加了两次。我到处都在寻找答案,甚至在FB的群组中,没有人知道该说什么。请帮帮忙。下面是我的整个servlet:

代码语言:javascript
复制
@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中查看表时出现的一些错误:

代码语言:javascript
复制
    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上的另一个视图

EN

回答 1

Stack Overflow用户

发布于 2019-02-06 23:11:38

我通过设置Tomcat服务器只运行而不立即加载页面来解决我的问题。当Tomcat运行时,我手动转到浏览器和加载页面,然后它只添加一次记录。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/54360859

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档