Java SQL Execute execute(Connection connection, String sql)

Here you can find the source of execute(Connection connection, String sql)

Description

Executes provided sql string

License

Open Source License

Declaration

public static boolean execute(Connection connection, String sql) throws SQLException 

Method Source Code

//package com.java2s;
//License from project: Open Source License 

import java.sql.*;

public class Main {
    /**/*  w ww.  j a v a  2s . co m*/
     * Executes provided sql string
     */
    public static boolean execute(Connection connection, String sql) throws SQLException {
        PreparedStatement statement = null;
        try {
            statement = connection.prepareStatement(sql);
            return statement.execute();
        } finally {
            closeQuietly(statement);
        }
    }

    /**
     * Closes provided {@link ResultSet} without throwing exception
     *
     * @param rs {@link ResultSet} to close
     */
    public static void closeQuietly(ResultSet rs) {
        if (rs != null) {
            try {
                rs.close();
            } catch (Exception e) {
                //ignore
            }
        }
    }

    /**
     * Closes provided {@link Statement} without throwing exception
     *
     * @param statement {@link Statement} to close
     */
    public static void closeQuietly(Statement statement) {
        if (statement != null) {
            try {
                statement.close();
            } catch (Exception e) {
                //ignore
            }
        }
    }

    /**
     * Closes provided {@link Connection} without throwing exception
     *
     * @param connection {@link Connection} to close
     */
    public static void closeQuietly(Connection connection) {
        if (connection != null) {
            try {
                connection.close();
            } catch (Exception e) {
                //ignore
            }
        }
    }
}

Related

  1. execte(Connection conn, String sql)
  2. execute(Connection conn, String SQL)
  3. execute(Connection conn, String sql, Object[] args)
  4. execute(Connection conn, String sql, Object[] params)
  5. execute(Connection conn, String string)
  6. execute(Connection connection, String sql, boolean closeConn)
  7. execute(final String url, final String username, final String password, final String sql, final Consumer consumer)
  8. execute(List sql)
  9. execute(Statement statement, String sql)