package com.fp.report.db;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.util.ArrayList;
import java.util.List;

public class SQLUtil {
    public static Object execute(Connection pCon, String pSQL, Object[] pParams) throws Exception {
        ArrayList<?> a;
        PreparedStatement pst = pCon.prepareStatement(pSQL);
        ResultSet rst = null;
        try {
            if (pParams != null) {
                for (int i = 0; i < pParams.length; i++) {
                    Object object = pParams[i];
                    pst.setObject(i + 1, object);
                }
            }
            rst = pst.executeQuery();
            return (rst.next()) ? rst.getObject(1) : null;
        } finally {
            if (rst != null) {
                rst.close();
            }
            if (pst != null) {
                pst.close();
            }
        }
    }

    public static List<Object> prepareParameter(List<Object> pData, Object newParam) {
        List<Object> data = (pData == null) ? new ArrayList<Object>() : pData;
        data.add(newParam);
        return data;
    }
}
