Here you can find the source of prepareStatementForwardReadOnly(Connection conn, String name, String sql)
Parameter | Description |
---|---|
SQLException | an exception |
public static final PreparedStatement prepareStatementForwardReadOnly(Connection conn, String name, String sql) throws SQLException
//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; } }