⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 sqlutil.java

📁 国外的一套开源CRM
💻 JAVA
字号:
/*
 * 
 * Copyright (c) 2004 SourceTap - www.sourcetap.com
 *
 *  The contents of this file are subject to the SourceTap Public License 
 * ("License"); You may not use this file except in compliance with the 
 * License. You may obtain a copy of the License at http://www.sourcetap.com/license.htm
 * Software distributed under the License is distributed on an  "AS IS"  basis,
 * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License for
 * the specific language governing rights and limitations under the License.
 *
 * The above copyright notice and this permission notice shall be included
 * in all copies or substantial portions of the Software.
 *
 */

package com.sourcetap.sfa.sql;

import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;

import org.ofbiz.base.util.Debug;
import org.ofbiz.entity.GenericDelegator;
import org.ofbiz.entity.GenericEntityException;
import org.ofbiz.entity.jdbc.ConnectionFactory;


/**
 * DOCUMENT ME!
 *
 */
public class SQLUtil {
	public static final String module = SQLUtil.class.getName();
    String helperName = null;

    public SQLUtil() {
    }

    /**
     * DOCUMENT ME!
     *
     * @param delegator 
     *
     * @return 
     */
    public Connection getConnection(GenericDelegator delegator) {
        Connection connection = null;

        if (helperName == null) {
            helperName = delegator.getEntityHelperName("UiScreen");
        }

        try {
            connection = ConnectionFactory.getConnection(helperName);
        } catch (SQLException sqle) {
            Debug.logError(
                "[SQLUtil.getConnection]: Unable to esablish a connection with the database... Error was:", module);
            Debug.logError(sqle.getMessage(), module);
        } catch (GenericEntityException gee) {
            Debug.logError(
                "[SQLUtil.getConnection]: Unable to esablish a connection with the database... Error was:", module);
            Debug.logError(gee.getMessage(), module);
        }

        return connection;
    }

    /**
     * DOCUMENT ME!
     *
     * @param delegator 
     * @param sqlStmt 
     *
     * @return 
     */
    public ResultSet executeSQL(GenericDelegator delegator, String sqlStmt) {
        Statement stmt = null;
        ResultSet rs = null;
        Connection conn = null;

        try {
            conn = getConnection(delegator);
            stmt = conn.createStatement();
            rs = stmt.executeQuery(sqlStmt);

            return rs;
        } catch (SQLException sqle) {
            Debug.logError(
                "[SQLUtil.executeSQL]: SQL Exception while executing the following:\n" +
                sqlStmt + "\nError was:", module);
            Debug.logError(sqle.getMessage(), module);

            return null;
        } finally {
            try {
                if (stmt != null) {
                    stmt.close();
                }
            } catch (SQLException sqle) {
            }

            try {
                if (conn != null) {
                    conn.close();
                }
            } catch (SQLException sqle) {
            }
        }
    }
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -