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

📄 dbexecute.java

📁 java阿里巴巴代码
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
package com.saas.sys.dbm;

import java.sql.*;
import java.util.*;
import java.io.*;
import org.apache.commons.beanutils.PropertyUtils;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Iterator;
import java.lang.reflect.Field;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import com.saas.sys.buffer.*;

import com.saas.sys.log.Logger;

public class Dbexecute {
	
	private Connection connectionHandle = null;
	
	private ArrayList queryList = new ArrayList();
	
	private ArrayList paramList = new ArrayList();
	
	private String strQuery;
	
	private String strTable;
	
	private Dbcommit commit;
	
	Dbtable query = new Dbtable();
	
	Logger log = new Logger(this);
	
	
	/**
	 * Returns the rsrv_str4.
	 * 
	 * @return String
	 */
	public Connection getConnectionHandle() {

		return connectionHandle;
	}
	
	public void setConnectionHandle(Connection connectionHandle) {

		this.connectionHandle = connectionHandle;
	}
	
	public String getStrTable() {

		return strTable;
	}
	
	public void setStrTable(String strTable) {

		this.strTable = strTable;
	}
	
	
	public ArrayList getQueryList() {

		return queryList;
	}
	
	public String getStrQuery() {

		return strQuery;
	}
	
	public void setStrQuery(String strQuery) {

		this.strQuery = strQuery;
	}
	
	public void setQueryList(ArrayList queryList) {

		this.queryList = queryList;
	}
	
	public void addStrQuery(String strQuery) {

		this.queryList.add(strQuery);
	}
	
	
	public ArrayList getParamList() {

		return paramList;
	}
	
	public void setParamList(ArrayList inArray) {

		this.paramList = inArray;
	}
	
	/**
	 * @author: Wangrc
	 * @Date: 2006-6-18 20:44:46
	 * @Method Name: ExecInsert
	 */
	public void execBizQuery() {

		PreparedStatement stm = null;
		
		if (this.queryList.isEmpty()) {
			return;
			// throw new RuntimeException("SQL语句为空,请检查程序!");
		}
		
		for (Iterator it = this.queryList.iterator(); it.hasNext();) {
			ArrayList queryList = (ArrayList) it.next();
			for (Iterator itq = queryList.iterator(); itq.hasNext();) {
				HashMap queryMap = (HashMap) itq.next();
				if (queryMap.get("queryString") != null) {
					String queryStr = queryMap.get("queryString").toString();
					
					this.strTable = queryMap.get("queryTable").toString();
					this.strQuery = queryMap.get("queryString").toString();
					ArrayList queryParamList = (ArrayList) queryMap.get("queryVarMap");
					try {
						this.strQuery = this.getQuery();
						this.paramList = queryParamList;
						ArrayList paraOrder = this.replaceQueryParam();
						if (stm != null)
							stm.clearParameters();
						stm = this.connectionHandle.prepareStatement(this.strQuery);
						log.LOG_INFO(this.strQuery);
						this.setQueryParam(stm, paraOrder);
						stm.executeUpdate();
					}
					catch (SQLException e) {
						throw new RuntimeException(e);
					}
					catch (Exception e) {
						throw new RuntimeException(e);
					}
					
				}
			}
		}
		/***********************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************
		 * for(int i=0;i<this.queryList.size();i++) { String sqlStr=(String)this.queryList.get(i); try { this.strQuery = this.getQuery(); ArrayList paraOrder = this.replaceQueryParam(); if (stm !=null) stm.clearParameters(); stm=this.connectionHandle.prepareStatement(this.strQuery); log.LOG_INFO("strQuery::->>>"+this.strQuery); this.setQueryParam(stm,paraOrder); stm.executeUpdate(); } catch (SQLException e) { throw new RuntimeException(e); } catch (Exception e) { throw new RuntimeException(e); } }
		 **********************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************/
		this.queryList.clear();
	}
	
	/**
	 * @author: Wangrc
	 * @Date: 2006-6-18 20:44:46
	 * @Method Name: SelBizQuery
	 */
	public ArrayList selBizQuery() {

		Dbcommit tempConnect = new Dbcommit();
		tempConnect.getConnect();
		Connection tempConnectHandle = tempConnect.getConnectionHandle();
		PreparedStatement stm = null;
		ResultSet rst = null;
		
		ResultSetMetaData rstMetaDate = null;
		ArrayList dataArray = new ArrayList();
		int columnCount = 0;
		try {
			this.strQuery = this.getQuery();
			ArrayList paraOrder = this.replaceQueryParam();
			if (stm != null)
				stm.clearParameters();
			// this.strQuery ="select * from (select a.*, rownum rn from ("+this.strQuery+" ) a where rownum <= 100)where rn >= 0";
			stm = tempConnectHandle.prepareStatement(this.strQuery);
			this.setQueryParam(stm, paraOrder);
			rst = stm.executeQuery();
			rstMetaDate = rst.getMetaData();
			columnCount = rstMetaDate.getColumnCount();
			
		}
		catch (SQLException e) {
			throw new RuntimeException(e);
		}
		
		try {
			while (rst.next()) {
				HashMap row = new HashMap();
				for (int i = 1; i <= columnCount; i++) {
					String strFieldName = rstMetaDate.getColumnName(i).toLowerCase();
					
					if (rstMetaDate.getColumnTypeName(i) == "VARCHAR2" || rstMetaDate.getColumnTypeName(i) == "CHAR" || rstMetaDate.getColumnTypeName(i) == "DATE") {
						if (rst.getObject(i) != null) {
							row.put(strFieldName, rst.getObject(i).toString());
						}
						else {
							row.put(strFieldName, rst.getObject(i));
						}
					}
					else if (rstMetaDate.getColumnTypeName(i) == "LONG") {
						if (rst.getCharacterStream(i) != null) {
							java.io.Reader reader = (java.io.Reader) rst.getCharacterStream(i);
							String strtmp = "";
							try {
								strtmp = (String) getLargerString(reader);
								row.put(strFieldName, strtmp);
							}
							catch (Exception e) {
								throw new RuntimeException(e);
							}
						}
						else {
							row.put(strFieldName, "");
						}
					}
					else {
						row.put(strFieldName, rst.getObject(i));
					}
					
				}
				dataArray.add(row);
			}
		}
		catch (SQLException e) {
			tempConnect.closeConn();
			throw new RuntimeException(e);
		}
		tempConnect.closeConn();
		return dataArray;
	}
	
	public void addTable(Dbtable query) {

		this.setQueryList(query.getExecuteBy());
	}
	
	public String convetStrToWeb(String str) {

		String outstr = "";
		if (str == null || str == "") {
			outstr = "";
		}

⌨️ 快捷键说明

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