Java SQL Update executeUpdateNoCommit(Connection c, String query)

Here you can find the source of executeUpdateNoCommit(Connection c, String query)

Description

executeUpdateNoCommit

License

Open Source License

Parameter

Parameter Description
c c
query query

Exception

Parameter Description
SQLException SQLException

Return

DOCUMENT ME!

Declaration

public static int executeUpdateNoCommit(Connection c, String query) throws SQLException 

Method Source Code


//package com.java2s;
import java.sql.Connection;

import java.sql.SQLException;
import java.sql.Statement;

public class Main {
    /**//from  w  w  w . j a  v  a  2  s  .  c  o  m
     * executeUpdateNoCommit
     * 
     * @param c
     *            c
     * @param query
     *            query
     * 
     * @return DOCUMENT ME!
     * 
     * @throws SQLException
     *             SQLException
     */
    public static int executeUpdateNoCommit(Connection c, String query) throws SQLException {
        int rowsUpdated = -1;
        Statement st = c.createStatement();

        try {
            rowsUpdated = st.executeUpdate(query);
        } catch (SQLException ee) {
            throw ee;
        } finally {
            try {
                if (st != null) {
                    st.close();
                }
            } catch (Exception ex) {
            }
        }
        return rowsUpdated;
    }

    /**
     * executeUpdate
     * 
     * @param c
     *            c
     * @param query
     *            query
     * 
     * @return DOCUMENT ME!
     * 
     * @throws SQLException
     *             SQLException
     */
    public static int executeUpdate(Connection c, String query) throws SQLException {
        int rowsUpdated = -1;
        Statement st = c.createStatement();

        try {
            rowsUpdated = st.executeUpdate(query);
        } catch (SQLException ee) {
            System.err.println("Caught while running query\t" + query);
            ee.printStackTrace();
            throw ee;
        } finally {
            try {
                if (st != null) {
                    st.close();
                }
            } catch (Exception ex) {
            }
        }
        return rowsUpdated;
    }
}

Related

  1. executeUpdate(PreparedStatement preparedStatement, List paramList)
  2. executeUpdate(PreparedStatement ps)
  3. executeUpdate(String parameterizedSQL, List values, Connection conn)
  4. executeUpdate(String queryStatement, Connection database)
  5. ExecuteUpdate(String sql, List paras)
  6. executeUpdatePreparedStm(Connection conn, String preparedStm, Object... sqlParameters)
  7. ExecuteUpdateQuery(String query, Connection con)
  8. executeUpdateSP(Connection conn, String spName, Object... sqlParameters)
  9. ExecuteUpdateStmt(Connection conn, PreparedStatement pstmt, PreparedStatement lockStatement, String tablename)

  10. HOME | Copyright © www.java2s.com 2016