簡體   English   中英

JDBC驅動程序中的Statement,PreparedStatement和CallableStatement的ExecuteUpdate實現是否有所不同?

[英]Does implementation of ExecuteUpdate is different for Statement,PreparedStatement and CallableStatement inside JDBC driver?

BackGroud故事

我發現Sybase JDBC驅動程序(jconn3)在Statement.ExecuteUpdate(sql).上吃了異常Statement.ExecuteUpdate(sql).
SQL語句是一個Insert語句,它將行插入到表(這不是臨時表)中,但由於未知原因, Statement.ExecuteUpdate(sql)仍返回0。 此問題是隨機的,似乎並非每次都發生。

我的理解是Statement.ExecuteUpdate(sql)如果未更新任何行,則返回0。 但是就插入語句而言,我不確定為什么什么也沒插入就不會拋出異常。
由於該代碼是舊版代碼(正在使用JDK 1.4),由於某些限制,我無法更改或更新JDBC驅動程序。


可能的:

我正從一個角度考慮驅動程序在Statement,PreparedStatement和CallableStatement方面是否具有ExecuteUpdate的不同內部實現,那么我可以建議將Statement更改為CallableStatement以調用ExecuteUpdate。

我想知道Sybase JDBC驅動程序中Statement,PreparedStatement和CallableStatement的ExecuteUpdate實現是否可能不同。

我想知道Sybase JDBC驅動程序中Statement,PreparedStatement和CallableStatement的ExecuteUpdate實現是否可能不同。

.executeUpdate的實現對於任何 JDBC驅動程序中的StatementPreparedStatement對象都是不同的,因為這兩個對象的工作方式不同。

Statement對象只是執行任意SQL語句的對象。 使用Connection#createStatement創建對象時,未提供SQL語句,但會將它作為參數傳遞給Statement#executeUpdate方法。

創建PreparedStatement對象要求在調用Connection#prepareStatement方法時提供SQL語句。 SQL語句是“預編譯的”,並作為對象的一部分進行緩存。 是時候執行語句了,我們只需要調用PreparedStatement#executeUpdate方法(不帶參數),因為SQL代碼已經“准備好了”。

由於必須Statement#executeUpdate提供一個參數,而不能PreparedStatement#executeUpdate提供一個參數,因此顯然必須以不同的方式實現。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM