Java SQL PreparedStatement prepareStatement(Connection conn, Map psMap, String key, String sql)

Here you can find the source of prepareStatement(Connection conn, Map psMap, String key, String sql)

Description

prepare Statement

License

Open Source License

Declaration

public static PreparedStatement prepareStatement(Connection conn, Map psMap, String key, String sql)
            throws SQLException 

Method Source Code

//package com.java2s;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.SQLException;

import java.util.Map;

public class Main {
    public static PreparedStatement prepareStatement(Connection conn, Map psMap, String key, String sql)
            throws SQLException {
        Object[] obj = (Object[]) psMap.get(key);
        if (obj == null) {
            obj = new Object[] { null, null };
            psMap.put(key, obj);//from  w  ww  .  ja v a  2  s .  c om
        }

        String lastSql = (String) obj[0];
        PreparedStatement ps = (PreparedStatement) obj[1];
        if (!sql.equals(lastSql)) {
            if (ps != null)
                ps.close();
            obj[0] = sql;
            obj[1] = ps = conn.prepareStatement(sql);
        }

        return ps;
    }
}

Related

  1. loadColumnTableNameList(PreparedStatement stmt)
  2. LockRow(PreparedStatement pstmt, String tablename, boolean exclusiveMode)
  3. logPreparedStatement(PreparedStatement p)
  4. prepareStatement( Connection conn, String query, List params)
  5. prepareStatement(Connection con,String sql,Object...params)
  6. prepareStatement(Connection conn, String name, String sql)
  7. prepareStatement(Connection conn, String sql)
  8. prepareStatement(Connection conn, String sql, boolean isCallable)
  9. prepareStatement(Connection conn, String sql, Object... values)