Java Utililty Methods SQL Execute

List of utility methods to do SQL Execute

Description

The list of methods to do SQL Execute are organized into topic(s).

Method

voidexec(Connection conn, String sql)
exec
PreparedStatement pstmt = null;
try {
    pstmt = conn.prepareStatement(sql);
    pstmt.execute();
} finally {
    close(pstmt);
voidexec(Connection psql, String sql)
exec
Statement statement = psql.createStatement();
statement.execute(sql);
statement.close();
booleanexecSql(String sql, Connection conn)
exec Sql
PreparedStatement ps = conn.prepareStatement(sql);
boolean result = false;
try {
    ps.execute();
} finally {
    ps.close();
return result;
...
intexecStatement(Connection con, String strStatement)

Purpose: execute statement, can be used to do update or insert
Assumptions: Note: this version does not take into account special characters.
ResultSet rs = null;
PreparedStatement st = null;
try {
    st = con.prepareStatement(strStatement);
    return st.executeUpdate();
} finally {
    try {
        closeAll(rs, st, null);
...
voidexecte(Connection conn, String sql)
execte
Statement stat = conn.createStatement();
stat.execute(sql);
stat.close();
voidexecute(Connection conn, String SQL)
execute
Statement stmt = conn.createStatement();
try {
    stmt.execute(SQL.toString());
} catch (Exception ex) {
    System.out.println("Exception running SQL: " + SQL.toString());
    throw ex;
voidexecute(Connection conn, String sql, Object[] args)

Executes the given sql string.

PreparedStatement stmt = null;
try {
    stmt = conn.prepareStatement(sql);
    for (int i = 0; i < args.length;) {
        Object obj = args[i++];
        if (obj instanceof Long) {
            stmt.setLong(i, ((Long) obj).longValue());
        } else if (obj instanceof Double) {
...
Listexecute(Connection conn, String sql, Object[] params)
execute
List<Object[]> result = new ArrayList<Object[]>();
PreparedStatement ps = null;
ResultSet rs = null;
try {
    ps = conn.prepareStatement(sql);
    for (int i = 0; i < params.length; i++) {
        Object obj = params[i];
        ps.setObject(i + 1, obj);
...
intexecute(Connection conn, String string)
execute
PreparedStatement st = conn.prepareStatement(string);
try {
    return st.executeUpdate();
} finally {
    st.close();
booleanexecute(Connection connection, String sql)
Executes provided sql string
PreparedStatement statement = null;
try {
    statement = connection.prepareStatement(sql);
    return statement.execute();
} finally {
    closeQuietly(statement);