Java SQL PreparedStatement prepareStatementForwardReadOnly(Connection conn, String name, String sql)

Here you can find the source of prepareStatementForwardReadOnly(Connection conn, String name, String sql)

Description

prepare statements for this connection

License

Open Source License

Exception

Parameter Description
SQLException an exception

Declaration

public static final PreparedStatement prepareStatementForwardReadOnly(Connection conn, String name, String sql)
        throws SQLException 

Method Source Code

//package com.java2s;

import java.sql.Connection;

import java.sql.PreparedStatement;
import java.sql.ResultSet;

import java.sql.SQLException;

import java.sql.Statement;

public class Main {
    private static final boolean DEBUG_SQL = false;

    /**//from  w ww.j a  v  a 2 s.  c o  m
     * prepare statements for this connection
     *
     * @throws SQLException
     **/
    public static final PreparedStatement prepareStatementForwardReadOnly(Connection conn, String name, String sql)
            throws SQLException {
        PreparedStatement ps = null;
        try {
            ps = prepareForwardReadOnly(conn, sql);
        } finally {
            if (ps == null) {
                System.err.println("Warning: couldn't initialize " + name + " from " + sql);
            }
        }
        // if(false) System.out.println("EXPLAIN EXTENDED " +
        // sql.replaceAll("\\?", "'?'")+";");
        // } catch ( SQLException se ) {
        // String complaint = "Vetter:  Couldn't prepare " + name + " - " +
        // DBUtils.unchainSqlException(se) + " - " + sql;
        // logger.severe(complaint);
        // throw new RuntimeException(complaint);
        // }
        return ps;
    }

    /**
     * Shortcut for certain statements.
     *
     * @param conn
     * @param str
     * @return
     * @throws SQLException
     */
    public static final PreparedStatement prepareForwardReadOnly(Connection conn, String str) throws SQLException {
        if (DEBUG_SQL)
            System.out.println("SQL: " + str);
        return conn.prepareStatement(str, ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_READ_ONLY);
    }

    /**
     * prepare statements for this connection. Assumes generated keys.
     *
     * @throws SQLException
     **/
    public static final PreparedStatement prepareStatement(Connection conn, String name, String sql)
            throws SQLException {
        PreparedStatement ps = null;
        try {
            ps = conn.prepareStatement(sql, Statement.RETURN_GENERATED_KEYS);
        } finally {
            if (ps == null) {
                System.err.println("Warning: couldn't initialize " + name + " from " + sql);
            }
        }
        // if(false) System.out.println("EXPLAIN EXTENDED " +
        // sql.replaceAll("\\?", "'?'")+";");
        // } catch ( SQLException se ) {
        // String complaint = "Vetter:  Couldn't prepare " + name + " - " +
        // DBUtils.unchainSqlException(se) + " - " + sql;
        // logger.severe(complaint);
        // throw new RuntimeException(complaint);
        // }
        return ps;
    }
}

Related

  1. prepareStatement(Connection connection, String sql, boolean returnKeys, Object... values)
  2. prepareStatement(Connection connection, String sql, Object... values)
  3. prepareStatement(String parameterizedSQL, List values, Connection conn)
  4. prepareStatement(String parameterizedSQL, List values, Connection conn)
  5. prepareStatement(String query)
  6. putArgsToStatement(PreparedStatement stmt, List args)
  7. query(List paramList, Connection conn, PreparedStatement pstmt)
  8. runInsertLong(PreparedStatement s)
  9. saveResourceInfoRecord(long resourceId, long propertyId, String propertyValue, String userId, PreparedStatement ps)

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