Mercurial > hg > monetdb-java
view tests/BugExecuteUpdate_Bug_3350.java @ 128:a6a2f4ee2d42 v2.25
Updated release numbers in preparation for a release.
author | Sjoerd Mullender <sjoerd@acm.org> |
---|---|
date | Thu, 30 Mar 2017 15:31:35 +0200 (2017-03-30) |
parents | b9b35ca2eec2 |
children | f9ba2b04db7b |
line wrap: on
line source
/* * This Source Code Form is subject to the terms of the Mozilla Public * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at http://mozilla.org/MPL/2.0/. * * Copyright 1997 - July 2008 CWI, August 2008 - 2017 MonetDB B.V. */ import java.sql.*; public class BugExecuteUpdate_Bug_3350 { public static void main(String[] args) throws Exception { // Class.forName("nl.cwi.monetdb.jdbc.MonetDriver"); // not needed anymore for self registering JDBC drivers final Connection con = DriverManager.getConnection(args[0]); con.setAutoCommit(false); // disable auto commit, so we can roll back the transaction final Statement stmt = con.createStatement(); try { executeDML(stmt, "INSERT INTO sys.keywords VALUES ('Bug_3350')"); // should insert 1 row executeDML(stmt, "INSERT INTO sys.keywords VALUES ('Bug_3350')"); // this will result in an SQLException due to PK uniqueness violation con.rollback(); executeDML(stmt, "INSERT INTO sys.keywords VALUES ('Bug_3350')"); // should insert 1 row executeDML(stmt, "DELETE FROM sys.keywords WHERE \"keyword\" = 'Bug_3350'"); // should delete 1 row executeDML(stmt, "DELETE FROM sys.keywords WHERE \"keyword\" = 'Bug_3350'"); // should delete 0 rows con.rollback(); } catch (SQLException se) { System.out.println(se.getMessage()); } finally { stmt.close(); } con.close(); } private static void executeDML(Statement st, String sql) { try { int upd_count = st.executeUpdate(sql); System.out.println("executeUpdate(" + sql.substring(0, 6) + " ...) returned: " + upd_count); } catch (SQLException se) { System.out.println(se.getMessage()); } try { System.out.println("getUpdateCount() returned: " + st.getUpdateCount()); } catch (SQLException se) { System.out.println(se.getMessage()); } } }