Code example for Connection

Methods: closeprepareStatement

0
    { 
        if (conn != null)
        { 
            try 
            { 
                conn.close();
            } 
            catch (RuntimeException re)
            { 
                throw re;
            } 
            catch (Exception e)
            { 
                String msg = "DataSourceResourceLoader: problem when closing connection";
                log.error(msg, e);
                throw new VelocityException(msg, e);
            } 
        } 
    } 
 
    /** 
     * Closes the result set. 
     */ 
    private void closeResultSet(final ResultSet rs)
    { 
        if (rs != null)
        { 
            try 
            { 
                rs.close();
            } 
            catch (RuntimeException re)
            { 
                throw re;
            } 
            catch (Exception e)
            { 
                String msg = "DataSourceResourceLoader: problem when closing result set";
                log.error(msg, e);
                throw new VelocityException(msg, e);
            } 
        } 
    } 
     
    /** 
     * Closes the PreparedStatement. 
     */ 
    private void closeStatement(PreparedStatement ps)
    { 
        if (ps != null)
        { 
            try 
            { 
                ps.close();
            } 
            catch (RuntimeException re)
            { 
                throw re;
            } 
            catch (Exception e)
            { 
                String msg = "DataSourceResourceLoader: problem when closing PreparedStatement ";
                log.error(msg, e);
                throw new VelocityException(msg, e);
            } 
        } 
    } 
         
 
    /** 
     * Creates the following PreparedStatement query : 
     * <br> 
     *  SELECT <i>columnNames</i> FROM <i>tableName</i> WHERE <i>keyColumn</i> 
     *     = '<i>templateName</i>' 
     * <br> 
     * where <i>keyColumn</i> is a class member set in init() 
     * 
     * @param conn connection to datasource 
     * @param columnNames columns to fetch from datasource 
     * @param templateName name of template to fetch 
     * @return PreparedStatement 
     */ 
    private PreparedStatement getStatement(final Connection conn,
                               final String columnNames,
                               final String templateName) throws SQLException
    { 
        PreparedStatement ps = conn.prepareStatement("SELECT " + columnNames + " FROM "+ tableName + " WHERE " + keyColumn + " = ?");
        ps.setString(1, templateName);
        return ps;
    } 
 
} 
Connect your IDE to all the code out there  Get Codota for Java