public class AccessDataBaseConnection implements IConnection {
	
	/**
	 * 构造函数
	 * @param conn
	 */
	//初始化jdbc
	static
	{
		try 
		{
			Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
		} 
		catch (ClassNotFoundException e)
		{
			// TODO Auto-generated catch block
			e.printStackTrace();
			DBCException.logException(DBCException.E_LoadJDBC, e);
		}
	}	

	/* (non-Javadoc)
	 * @see com.ojdbc.sql.IDataBase#createConnection(java.lang.String, java.lang.String, java.lang.String)
	 */
	/**
	 * 示例
	 * dataBaseURL: e://student.mdb 
	 * userName: null
	 * passWord: null
	 */
	@Override
	public Connection createConnection(String dataBaseURL, String userName,
			String passWord) {
		// TODO Auto-generated method stub
		Connection conn = null;
		String url = "jdbc:odbc:driver={Microsoft Access Driver (*.mdb)};DBQ="+dataBaseURL;
		try 
		{
			conn = DriverManager.getConnection(url,userName,passWord);
		} 
		catch (SQLException e) 
		{
			// TODO Auto-generated catch block
			e.printStackTrace();
			DBCException.logException(DBCException.E_GetConnection, e);
			return null;
		}
		return conn;
	}

}
 public class MongoDataBaseConnection implements IConnection {
	
	//初始化jdbc
	static
	{
		try 
		{
			Class.forName("mongodb.jdbc.MongoDriver");
		} 
		catch (ClassNotFoundException e)
		{
			// TODO Auto-generated catch block
			e.printStackTrace();
			DBCException.logException(DBCException.E_LoadJDBC, e);
		}
	}	

	/* (non-Javadoc)
	 * @see com.ojdbc.sql.IDataBase#createConnection(java.lang.String, java.lang.String, java.lang.String)
	 */
	/**
	 * 示例
	 * dataBaseURL: jdbc:mongo://127.0.0.1:29847/test
	 * userName: root
	 * passWord: root
	 */
	@Override
	public Connection createConnection(String dataBaseURL, String userName,
			String passWord) {
		// TODO Auto-generated method stub
		Connection conn = null;
		try 
		{
			conn = DriverManager.getConnection(dataBaseURL,userName,passWord);
		} 
		catch (SQLException e) 
		{
			// TODO Auto-generated catch block
			e.printStackTrace();
			DBCException.logException(DBCException.E_GetConnection, e);
			return null;
		}
		return conn;
	}

}
 public class MySQLDataBaseConnection implements IConnection {

	//初始化jdbc
	static
	{
		try 
		{
			Class.forName("com.mysql.jdbc.Driver");
		} 
		catch (ClassNotFoundException e)
		{
			// TODO Auto-generated catch block
			e.printStackTrace();
			DBCException.logException(DBCException.E_LoadJDBC, e);
		}
	}
	/* (non-Javadoc)
	 * @see com.ojdbc.sql.IDataBase#createConnection(java.lang.String, java.lang.String, java.lang.String)
	 */
	/**
	 * 示例
	 * dataBaseURL: jdbc:mysql://127.0.0.1:3306/test
	 * userName: root
	 * passWord: root
	 */
	@Override
	public Connection createConnection(String dataBaseURL, String userName,
			String passWord) {
		// TODO Auto-generated method stub
		Connection conn = null;
		try 
		{
			conn = DriverManager.getConnection(dataBaseURL,userName,passWord);
		} 
		catch (SQLException e) 
		{
			// TODO Auto-generated catch block
			e.printStackTrace();
			DBCException.logException(DBCException.E_GetConnection, e);
			return null;
		}
		return conn;
	}	

}
 public class OracleDataBaseConnection implements IConnection {
	
	//初始化jdbc
	static
	{
		try 
		{
			Class.forName("oracle.jdbc.driver.OracleDriver");
		} 
		catch (ClassNotFoundException e)
		{
			// TODO Auto-generated catch block
			e.printStackTrace();
			DBCException.logException(DBCException.E_LoadJDBC, e);
		}
	}		

	/* (non-Javadoc)
	 * @see com.ojdbc.sql.IDataBase#createConnection(java.lang.String, java.lang.String, java.lang.String)
	 */
	/**
	 * 示例
	 * dataBaseURL: jdbc:oracle:thin:@127.0.0.1:1521:orcl
	 * userName: root
	 * passWord: root
	 */
	@Override
	public Connection createConnection(String dataBaseURL, String userName,
			String passWord) {
		// TODO Auto-generated method stub
		Connection conn = null;
		try 
		{
			conn = DriverManager.getConnection(dataBaseURL,userName,passWord);
		} 
		catch (SQLException e) 
		{
			// TODO Auto-generated catch block
			e.printStackTrace();
			DBCException.logException(DBCException.E_GetConnection, e);
			return null;
		}
		return conn;
	}

}
 public class PostgreSQLDataBaseConnection implements IConnection {

	//初始化jdbc
	static
	{
		try 
		{
			Class.forName("org.postgresql.Driver");
		} 
		catch (ClassNotFoundException e)
		{
			// TODO Auto-generated catch block
			e.printStackTrace();
			DBCException.logException(DBCException.E_LoadJDBC, e);
		}
	}		

	/* (non-Javadoc)
	 * @see com.ojdbc.sql.IDataBase#createConnection(java.lang.String, java.lang.String, java.lang.String)
	 */
	/**
	 * 示例
	 * dataBaseURL: jdbc:postgresql://127.0.0.1:5432/postgis
	 * userName: root
	 * passWord: root
	 */
	@Override
	public Connection createConnection(String dataBaseURL, String userName,
			String passWord) {
		// TODO Auto-generated method stub
		Connection conn = null;
		try 
		{
			conn = DriverManager.getConnection(dataBaseURL,userName,passWord);
		} 
		catch (SQLException e) 
		{
			// TODO Auto-generated catch block
			e.printStackTrace();
			DBCException.logException(DBCException.E_GetConnection, e);
			return null;
		}
		return conn;
	}

}
 public class SQLServerDataBaseConnection implements IConnection {

	//初始化jdbc
	static
	{
		try 
		{
			Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver");
		} 
		catch (ClassNotFoundException e)
		{
			// TODO Auto-generated catch block
			e.printStackTrace();
			DBCException.logException(DBCException.E_LoadJDBC, e);
		}
	}

	/* (non-Javadoc)
	 * @see com.ojdbc.sql.IDataBase#createConnection(java.lang.String, java.lang.String, java.lang.String)
	 */
	/**
	 * 示例
	 * dataBaseURL: jdbc:sqlserver://127.0.0.1:1433;DatabaseName=test
	 * userName: root
	 * passWord: root
	 */
	@Override
	public Connection createConnection(String dataBaseURL, String userName,
			String passWord) {
		// TODO Auto-generated method stub
		Connection conn = null;
		try 
		{
			conn = DriverManager.getConnection(dataBaseURL,userName,passWord);
		} 
		catch (SQLException e) 
		{
			// TODO Auto-generated catch block
			e.printStackTrace();
			DBCException.logException(DBCException.E_GetConnection, e);
			return null;
		}
		return conn;
	}

}
 public class SQLiteDataBaseConnection implements IConnection {

	//初始化jdbc
	static
	{
		try 
		{
			Class.forName("org.sqlite.JDBC");
		} 
		catch (ClassNotFoundException e)
		{
			// TODO Auto-generated catch block
			e.printStackTrace();
			DBCException.logException(DBCException.E_LoadJDBC, e);
		}
	}	

	/* (non-Javadoc)
	 * @see com.ojdbc.sql.IDataBase#createConnection(java.lang.String, java.lang.String, java.lang.String)
	 */
	/**
	 * 示例
	 * dataBaseURL: jdbc:sqlite://d:/test.db
	 * userName: null
	 * passWord: null
	 */
	@Override
	public Connection createConnection(String dataBaseURL, String userName,
			String passWord) {
		// TODO Auto-generated method stub
		Connection conn = null;
		String path = dataBaseURL;
		int length = dataBaseURL.indexOf("//")+2;
		if(length < dataBaseURL.length())
		{
			path = dataBaseURL.substring(length);
		}
		File file = new File(path);
		if(!file.getParentFile().exists())
		{
			file.getParentFile().mkdirs();
		}
		try 
		{
			conn = DriverManager.getConnection(dataBaseURL);
		} 
		catch (SQLException e) 
		{
			// TODO Auto-generated catch block
			e.printStackTrace();
			DBCException.logException(DBCException.E_GetConnection, e);
			return null;
		}
		return conn;
	}

}
 public class AccessDataBase extends DataBase {

	public AccessDataBase(ConnectionInfo connInfo) {
		super(connInfo);
		// TODO Auto-generated constructor stub
	}

}
 public class MongoDataBase extends DataBase {

	public MongoDataBase(ConnectionInfo connInfo) {
		super(connInfo);
		// TODO Auto-generated constructor stub
	}

}
 public class MySQLDataBase extends DataBase {

	public MySQLDataBase(ConnectionInfo connInfo) {
		super(connInfo);
		// TODO Auto-generated constructor stub
	}


}
 public class OracleDataBase extends DataBase {

	public OracleDataBase(ConnectionInfo connInfo) {
		super(connInfo);
		// TODO Auto-generated constructor stub
	}
	
	@Override
	public int exeSQLInsert(String sql) {
		// TODO Auto-generated method stub
		ConnectionObject conn = ConnectionManager.borrowConnectionObject(connInfo);
		Statement stat = null;
		try 
		{
			stat = conn.getConnection().createStatement();
			//stat.executeUpdate(sql);
			stat.executeUpdate(sql);
			return 1;
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
			DBCException.logException(DBCException.E_SQL, e);
			return 0;
		}
		finally
		{
			if(stat != null)
			{
				try 
				{
					stat.close();
				} catch (Exception e) {
					// TODO Auto-generated catch block
					e.printStackTrace();
				}
			}
			ConnectionManager.returnConnectionObject(conn);
		}
	}
	
	@Override
	public int exePreparedSQLInsert(String sql, PreparedParam preparedParam) {
		// TODO Auto-generated method stub
		ConnectionObject conn = ConnectionManager.borrowConnectionObject(connInfo);
		PreparedStatement preStmt = null;
		try 
		{
			preStmt = conn.getConnection().prepareStatement(sql,Statement.RETURN_GENERATED_KEYS);
			SQLPreparedParamUtil.setSQLPreparedParam(preStmt, preparedParam);
			preStmt.executeUpdate();
			return 1;
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
			DBCException.logException(DBCException.E_SQL, e);
			return 0;
		}
		finally
		{
			if(preStmt != null)
			{
				try 
				{
					preStmt.close();
				} catch (Exception e) {
					// TODO Auto-generated catch block
					e.printStackTrace();
				}
			}
			ConnectionManager.returnConnectionObject(conn);
		}
	}

}
 public class PostgreSQLDataBase extends DataBase {

	public PostgreSQLDataBase(ConnectionInfo connInfo) {
		super(connInfo);
		// TODO Auto-generated constructor stub
	}

}
 public class SQLServerDataBase extends DataBase {

	public SQLServerDataBase(ConnectionInfo connInfo) {
		super(connInfo);
		// TODO Auto-generated constructor stub
	}

}
 public class SQLiteDataBase extends DataBase {

	public SQLiteDataBase(ConnectionInfo connInfo) {
		super(connInfo);
		// TODO Auto-generated constructor stub
	}

}

import com.ojdbc.sql.connection.AccessDataBaseConnection;
import com.ojdbc.sql.connection.MongoDataBaseConnection;
import com.ojdbc.sql.connection.MySQLDataBaseConnection;
import com.ojdbc.sql.connection.OracleDataBaseConnection;
import com.ojdbc.sql.connection.PostgreSQLDataBaseConnection;
import com.ojdbc.sql.connection.SQLServerDataBaseConnection;
import com.ojdbc.sql.connection.SQLiteDataBaseConnection;
import com.ojdbc.sql.database.AccessDataBase;
import com.ojdbc.sql.database.MongoDataBase;
import com.ojdbc.sql.database.MySQLDataBase;
import com.ojdbc.sql.database.OracleDataBase;
import com.ojdbc.sql.database.PostgreSQLDataBase;
import com.ojdbc.sql.database.SQLServerDataBase;
import com.ojdbc.sql.database.SQLiteDataBase;

/**
 * ClassName: DataBaseType.java
 * Date: 2017年5月16日
 */
package com.ojdbc.sql;


/**
 * Author: ShaoGaige
 * Description: 数据库类型枚举
 * Log: 
 */
public enum DataBaseEnum implements IDataSource {
	
	/**
	 * Oracle
	 */
	 ORACLE{
		 
		@Override
		public String getDataBaseName() {
			// TODO Auto-generated method stub
			return "Oracle";
		}

		@Override
		public IConnection getConnection() {
			// TODO Auto-generated method stub

			return new OracleDataBaseConnection();
