Here you can find the source of execStatement(Connection con, String strStatement)
Parameter | Description |
---|
public static int execStatement(Connection con, String strStatement) throws SQLException
//package com.java2s; /** Copyright (C) (MSA, Inc) All rights reserved. ** General Public License: http://www.opensource.org/licenses/gpl-license.php **///from ww w . jav a 2s. c o m import java.sql.*; public class Main { /** <br><em>Purpose:</em> execute statement, can be used to do update or insert * <br><em>Assumptions:</em> Note: this version does not take into account special characters. * You need a more sophisticated mechanism to take those into account. * @param con, Connection * @param strStatement, String the statement * @return either the row count for INSERT, UPDATE or DELETE statements; or 0 for SQL statements that return nothing * @exception SQLException **/ public static int execStatement(Connection con, String strStatement) throws SQLException { ResultSet rs = null; PreparedStatement st = null; try { st = con.prepareStatement(strStatement); return st.executeUpdate(); } finally { try { closeAll(rs, st, null); } catch (SQLException e) { } } } /** Convenience method for closing sql objects. Closing is tried on ** all objects, independent of errors/exceptions in previous closes. * @param rs ResultSet to be closed * @param st Statement (or subclass) to be closed * @param conn Connection to be closed * @exception SQLException when any problem occurs while closing objects */ public static void closeAll(ResultSet rs, Statement st, Connection conn) throws SQLException { try { if (rs != null) { rs.close(); } } finally { try { if (st != null) { st.close(); } } finally { if (conn != null) { conn.close(); } } } } }