SQLManager.java
资源名称:OA.rar [点击查看]
上传用户:mingda
上传日期:2017-06-20
资源大小:27691k
文件大小:4k
源码类别:
OA系统
开发平台:
Java
- package com.gforce.currency.database;
- /**
- * <p>Title: 吉力科技办公自动化系统</p>
- * <p>Description: 吉力科技办公自动化系统</p>
- * <p>Copyright: 版权所有 2003 (c) 西安吉力科技发展有限公司 Copyright (c) 2003 GForce Sceince & Technology</p>
- * <p>Company: 西安吉力科技发展有限公司 (GForce Sceince & Technology)</p>
- * @author 马登军
- * @version 1.0
- */
- import java.sql.*;
- import java.io.*;
- import com.gforce.currency.*;
- import com.gforce.currency.database.*;
- import java.util.*;
- public class SQLManager {
- /**
- * 创建私有构造函数,防止外部调用
- */
- private SQLManager() {
- }
- /**
- * 执行插入、修改、删除的sql语句
- * @param sqlString 要执行的SQL语句
- * @return 执行结果状态返回值,返回值大于0代表执行成功,否则执行错误
- */
- public static int ExcuteSQL(String sqlString) {
- Statement stmt = null;
- Connection con = null;
- int returnValue = -100;
- try {
- con = ConnectionPool.Instance().getConnection("access");
- if (con == null) {
- SystemOut.ErrOut("不能获取数据库连接!");
- return -101;
- }
- SystemOut.LogPrintLine(sqlString);
- stmt = con.createStatement();
- returnValue = stmt.executeUpdate(sqlString);
- stmt.close();
- ConnectionPool.Instance().SetConnFree("access", con);
- }
- catch (SQLException e) {
- SystemOut.InfoOut("sql语句执行异常!" + e.toString());
- try
- {
- ConnectionPool.Instance().SetConnFree("access", con);
- }
- catch(Exception err)
- {
- SystemOut.InfoOut("连接池“access”释放连接异常!" + e.toString());
- ConnectionPool.Instance().CloseConn("access", con);
- }
- if (e.getErrorCode() < 1) {
- ConnectionPool.Instance().CloseConn("access", con);
- }
- returnValue = -102;
- }
- return returnValue;
- }
- /**
- * 执行查询的SQL语句并返回结果集
- * @param sqlString 要执行的SQL语句
- * @return 查询结果集
- */
- public static Vector GetResultSet(String sqlString) {
- Vector vc = new Vector();
- ResultSet rs = null;
- Statement stmt = null;
- SystemOut.LogPrintLine(sqlString);
- Connection con = null;
- try {
- con = ConnectionPool.Instance().getConnection("access");
- if (con == null) {
- System.out.println("不能获取数据库连接.");
- return vc;
- }
- stmt = con.createStatement();
- rs = stmt.executeQuery(sqlString);
- if (!rs.wasNull()) {
- int j = 0;
- while (rs.next()) {
- Vector vt = new Vector();
- for (int i = 0; i < rs.getMetaData().getColumnCount(); i++) {
- try {
- Object oTempObject = rs.getObject(i + 1);
- if (! (oTempObject == null || oTempObject.equals(null))) {
- vt.add(oTempObject);
- }
- else {
- vt.add("");
- }
- }
- catch (Exception err) {
- vt.add("");
- }
- }
- vc.add(vt);
- j++;
- }
- SystemOut.InfoOut("共有" + j + "条记录!");
- }
- rs.close();
- stmt.close();
- ConnectionPool.Instance().SetConnFree("access", con);
- }
- catch (SQLException e) {
- SystemOut.InfoOut("sql语句执行异常!" + e.toString());
- try
- {
- ConnectionPool.Instance().SetConnFree("access", con);
- }
- catch(Exception err)
- {
- SystemOut.InfoOut("连接池“access”释放连接异常!" + e.toString());
- ConnectionPool.Instance().CloseConn("access", con);
- }
- if (e.getErrorCode() < 1) {
- ConnectionPool.Instance().CloseConn("access", con);
- }
- }
- return vc;
- }
- }