[pgsql-jp: 29086] setAutoCommit で Warning
Daichi Ueura
daichi @ lifeflow.jp
2003年 2月 18日 (火) 02:29:07 JST
上浦と申します。
PostgreSQLを7.2から7.3.2へバージョンアップし、
build 108のJDBCドライバを使用すると、setAutoCommitでWarningが発生します。
環境
--------------------
PostgreSQL 7.3.2
JDBC pg73jdbc3.jar(Build 108)
J2SE 1.4.1_01
RedHatLinux 7.2
--------------------
setAutoCommitで自動コミットモードをfalseにした後、trueに変更すると、
ログに「WARNING: COMMIT: no transaction in progress」と記録されます。
org.postgresql.jdbc1.AbstractJdbc1Connection の setAutoCommitメソッドを
見てみると、
--------------------
if (this.autoCommit == autoCommit)
return;
if (autoCommit)
{
if (haveMinimumServerVersion("7.3"))
{
//We do the select to ensure a transaction is in process
//before we do the commit to avoid warning messages
//from issuing a commit without a transaction in process
execSQL("select 1; commit; set autocommit = on;");
}
else
{
execSQL("end");
}
}
--------------------
となっていて、"select 1"を実行してトランザクションを開始してから
コミットしているのでWarningが出ないと思うのですが・・・
pg72jdbc2.jarを使用すると問題は起きません。
このWarinigはこちらの問題なのでしょうか?
よろしくお願いします。
サンプルソース
--------------------
import java.sql.DriverManager;
import java.sql.Connection;
import java.sql.Statement;
import java.sql.ResultSet;
import java.sql.SQLException;
public class DBTest {
public static void main(String[] args) {
Connection conn = null;
Statement st = null;
ResultSet rs= null;
try {
conn = DriverManager.getConnection(
"jdbc:postgresql://localhost/template1","user","password");
conn.setAutoCommit(false);
st = conn.createStatement();
rs = st.executeQuery("SELECT version()");
conn.commit();
} catch(SQLException e) {
e.printStackTrace();
try {
conn.rollback();
} catch (SQLException ex) {
ex.printStackTrace();
}
} finally {
try {
if (rs != null) {
rs.close();
}
if (st != null) {
st.close();
}
if (conn != null) {
conn.setAutoCommit(true);
conn.close();
}
} catch (SQLException e) {
e.printStackTrace();
}
}
}
}
--------------------
┛
┛ Daichi Ueura
┛
┛ Hiroshima City Univ, Department of Intelligent Systems.
┛ e-mail: (Private) daichi @ lifeflow.jp
┛ : (Office) daichi @ neu.co.jp
┛ : (Univ) g23010 @ cr.info.hiroshima-cu.ac.jp
┛
┛
pgsql-jp メーリングリストの案内