久久久久久久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(使用線程逐塊處理文件)
主站蜘蛛池模板: 日韩在线视频一区 | 性国产丰满麻豆videosex | 国产精品久久久久久久 | 性欧美xxxx | 久久av一区 | 欧美午夜在线 | 亚洲黄色av网站 | 性色视频 | 国产亚洲精品久久久优势 | 99精品网 | 伊人色综合久久天天五月婷 | 欧美一区二区三区在线播放 | 久久精彩视频 | 中文字幕加勒比 | 久久亚洲精品国产精品紫薇 | 色精品视频 | 日韩欧美在线免费 | 亚洲一区二区免费电影 | 国产中文在线 | 亚洲国产aⅴ精品一区二区 免费观看av | 天天玩天天干天天操 | 日韩电影a | 丁香五月缴情综合网 | 日韩中文字幕视频 | 99亚洲视频| 成人午夜网站 | 精品福利一区二区三区 | 欧美日韩在线免费观看 | 日韩在线观看 | 男女下面一进一出网站 | 91大片| 超碰超碰| 污污免费网站 | 91影视| 日韩av在线免费 | 91精品久久久久久久久中文字幕 | 亚洲国产精品一区 | 爱爱免费视频网站 | 国产欧美精品一区二区三区 | 日本三级播放 | 天堂在线免费视频 |