📄 mysqldaofactory.java
字号:
/* * XP Forum * * Copyright (c) 2002-2003 RedSoft Group. All rights reserved. * */package org.redsoft.forum.dao.mysql;import org.apache.commons.dbcp.BasicDataSource;import org.redsoft.forum.dao.AccountDAO;import org.redsoft.forum.dao.DAOFactory;import org.redsoft.forum.dao.ThreadDAO;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 2004/02/04 03:52:12 mustang 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!"); if ( source == null ) { source = initDatasource(); } return source.getConnection(); } public MysqlDAOFactory() { source = initDatasource(); } private static DataSource initDatasource() { BasicDataSource ds = new BasicDataSource(); ds.setDefaultAutoCommit( false ); ds.setDriverClassName( "org.gjt.mm.mysql.Driver" ); ds.setUrl( "jdbc:mysql://localhost/forum" ); ds.setUsername( "xpforum" ); ds.setPassword( "demo1234" ); ds.addConnectionProperty("useUnicode", "true"); ds.addConnectionProperty("characterEncoding", "gb2312"); return ds; } /** * set the data source * * @param theObj Data Source * @see org.redsoft.forum.ForumActionServlet#init() public void init(Object theObj) { source = (DataSource)theObj; GenericDataSource is deprecated in struts 1.1 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(); }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -