久久久久久久av_日韩在线中文_看一级毛片视频_日本精品二区_成人深夜福利视频_武道仙尊动漫在线观看

為什么即使沒有插入新行,executeUpdate 也會返回

why does executeUpdate return 1 even if no new row has been inserted?(為什么即使沒有插入新行,executeUpdate 也會返回 1?)
本文介紹了為什么即使沒有插入新行,executeUpdate 也會返回 1?的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

問題描述

這是我非常簡單的表(Postgres):

here is my very simple table (Postgres):

CREATE TABLE IF NOT EXISTS PERFORMANCE.TEST
(
test text NOT NULL UNIQUE
);

如果我嘗試使用以下命令從數據庫中插入字符串,一切都會按預期進行,毫不奇怪,數據庫中會出現一個新行.

if I try to insert a String using the command below FROM the database,everything works as expected, not surprisingly a new row appears in the DB.

insert into performance.test (test) values ('abbbbaw');

但是,如果我想通過 JDBC 插入字符串,則不會插入任何內容,盡管preparedStatement.executeUpdate() 總是返回 1.

However if I want to insert a String through JDBC, nothing gets inserted, although preparedStatement.executeUpdate() always returns 1.

以下是我的方法,它應該有效,但它沒有.如果我遺漏了一些明顯的東西,請告訴我.我想補充一點,我從來沒有收到任何 SQLException.

Below is my method that should be working but it does not. Please tell me if I am missing something obvious. I want to add that I never get any SQLException.

private void storePerformance() {
    Connection conn= initializePerformanceConnection();
    if (conn!= null) {
       PreparedStatement insertPS = null;
        try {
            insertPS = conn.prepareStatement("insert into performance.test (test) values (?)");
            insertPS.setString(1, queryVar);
             int i = insertPS.executeUpdate();
            LogManager.doLog(LOG, LOGLEVEL.INFO," numberofrows= "+i);

        }  catch (SQLException e) {
            LogManager.doLog(LOG, LOGLEVEL.INFO,"Inserting query failed = "+queryVar,e);
        }finally{
            if(insertPS != null){
                try {
                    insertPS.close();
                } catch (SQLException e) {
                    LogManager.doLog(LOG, LOGLEVEL.INFO,"Closing PreparedStatement failed = "+queryVar,e);
                }
            }
            try {
                conn.close();
            } catch (SQLException e) {
                LogManager.doLog(LOG, LOGLEVEL.INFO,"Closing performanceConnection failed= "+ queryVar, e);
            }
        }           
    }
}

推薦答案

不見了:

conn.commit();

(在 executeUpdate() 之后)

(after the executeUpdate())

實際上插入了一個新行,但數據庫立即回滾.

actually a new row was inserted but the DB rolled back immediately.

這篇關于為什么即使沒有插入新行,executeUpdate 也會返回 1?的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!

【網站聲明】本站部分內容來源于互聯網,旨在幫助大家更快的解決問題,如果有圖片或者內容侵犯了您的權益,請聯系我們刪除處理,感謝您的支持!

相關文檔推薦

How to wrap text around components in a JTextPane?(如何在 JTextPane 中的組件周圍環繞文本?)
MyBatis, how to get the auto generated key of an insert? [MySql](MyBatis,如何獲取插入的自動生成密鑰?[MySql])
Inserting to Oracle Nested Table in Java(在 Java 中插入 Oracle 嵌套表)
Java: How to insert CLOB into oracle database(Java:如何將 CLOB 插入 oracle 數據庫)
Why does Spring-data-jdbc not save my Car object?(為什么 Spring-data-jdbc 不保存我的 Car 對象?)
Use threading to process file chunk by chunk(使用線程逐塊處理文件)
主站蜘蛛池模板: 伊人热久久 | 欧美一级视频免费看 | 污污的网站在线观看 | 999免费视频 | 97日韩精品 | 黄色国产视频 | 日韩视频一区二区三区 | 男人天堂网址 | 久久精品免费一区二区 | 成人精品国产一区二区4080 | 一级黄色日本片 | 亚洲精品国产a久久久久久 中文字幕一区二区三区四区五区 | 91久久久久久久久久久久久 | 国产精品99一区二区 | 欧美日韩精品免费观看 | 毛片一级片 | 成人免费三级电影 | 欧美日韩国产在线观看 | 在线观看 亚洲 | 天天操 天天操 | 婷婷狠狠| 亚洲午夜精品 | 日本精品视频一区二区三区四区 | 国产精品久久久久久久久久免费看 | 2022精品国偷自产免费观看 | 欧美日韩精品久久久免费观看 | 91社区在线观看 | 亚洲高清在线观看 | 日本亚洲欧美 | 久草精品视频 | 久久久久久久国产精品 | 神马久久久久久久久久 | 中文字幕 欧美 日韩 | 欧美亚洲另类在线 | 午夜免费av | 亚洲精品国产成人 | 久久av资源网 | 久久亚洲一区二区三区四区 | 久久精品欧美一区二区三区不卡 | 国产精品久久久久久久久久不蜜臀 | 91免费看片 |