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

📄 mysqldaofactory.java

📁 一个功能较为完善的论坛
💻 JAVA
字号:
/*
 * XP Forum
 *
 * Copyright (c) 2002-2003 RedSoft Group.  All rights reserved.
 *
 */
package org.redsoft.forum.dao.mysql;

import org.redsoft.forum.dao.DAOFactory;
import org.redsoft.forum.dao.ThreadDAO;
import org.redsoft.forum.dao.AccountDAO;
import org.apache.struts.action.ActionServlet;
import org.apache.struts.util.GenericDataSource;

import javax.sql.DataSource;
import java.sql.Connection;
import java.sql.SQLException;

/**
 * MySQL implementation of DAO factory
 *
 * @author <a href="mailto:jwtronics@yahoo.com">John Wong</a>
 *
 * @version $Id: MysqlDAOFactory.java,v 1.1.1.1 2003/07/08 08:25:16 cinc Exp $
 */
public class MysqlDAOFactory extends DAOFactory {
	private static DataSource source = null;

	/**
	 * Get Connection of the data source. Used by Mysql implementation.
	 */
	public static Connection getConnection() throws SQLException {
		if(source == null) throw new SQLException("Data source has not been initialized!");
		return source.getConnection();
	}

	public MysqlDAOFactory() {
	}

	/**
	 * set the data source
	 *
	 * @param theObject Data Source
	 * @see org.redsoft.forum.ForumActionServlet#init()
	 */
	public void init(Object theObj) {
		source = (DataSource)theObj;

        if(source instanceof GenericDataSource) {
            GenericDataSource gds = (GenericDataSource) source;
            try {
                gds.close();
                gds.addProperty("useUnicode", "true");
                gds.addProperty("characterEncoding", "gb2312");
                gds.open();
            } catch (Exception e) {
                System.out.println("ERROR! GenericDataSource open failed! Please contact John Wong");
            }


        }
	}

	/**
     * Return Thread DAO object
     */
    public ThreadDAO getThreadDAO() {
		return new ThreadDAOmySql();
	}

    /**
     *  Return Account DAO object
     */
    public AccountDAO getAccountDAO() {
        return new AccountDAOmySql();
    }
}//EOC

⌨️ 快捷键说明

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