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

📄 studentdelegateimpl.java

📁 java编码:JavaCode_version01.rar
💻 JAVA
字号:
/**
 * 
 */
package com.waytojob.teaching.jdbc;

import java.io.IOException;
import java.io.InputStream;
import java.sql.SQLException;
import java.util.List;
import java.util.Properties;

/**
 * @author Administrator
 * 
 */
public class StudentDelegateImpl implements IStudentDelegate
{
	private static IStudentDao studentDao;
	static
	{
		InputStream is = StudentDelegateImpl.class
				.getResourceAsStream("/com/waytojob/teaching/jdbc/dao_config.properties");
		if (is != null)
		{
			Properties prop = new Properties();
			try
			{
				prop.load(is);
				String clzName=prop.getProperty("dao.name");
				if(clzName == null || clzName.length()==0)
				{
					studentDao=null;
				}
				else
				{
					studentDao=(IStudentDao)Class.forName(clzName).newInstance();
				}
			}
			catch (IOException e)
			{
				StudentDelegateImpl.studentDao=null;
				e.printStackTrace();
			}
			catch (InstantiationException e)
			{
				studentDao=null;
				e.printStackTrace();
			}
			catch (IllegalAccessException e)
			{
				studentDao=null;
				e.printStackTrace();
			}
			catch (ClassNotFoundException e)
			{
				studentDao=null;
				e.printStackTrace();
			}
		}
		else
		{
			StudentDelegateImpl.studentDao=null;
		}
	}

	/**
	 * 
	 */
	public StudentDelegateImpl()
	{
		super();
		// TODO 自动生成构造函数存根
	}

	/*
	 * (非 Javadoc)
	 * 
	 * @see com.waytojob.teaching.jdbc.IStudentDelegate#createTable(com.waytojob.teaching.jdbc.Table)
	 */
	public boolean createTable(Table table)
	{
		if(StudentDelegateImpl.studentDao==null)
		{
			return false;
		}
		try
		{
			StudentDelegateImpl.studentDao.createTable(table);
			return true;
		}
		catch (SQLException e)
		{
			// TODO 自动生成 catch 块
			e.printStackTrace();
		}
		return false;
	}

	/*
	 * (非 Javadoc)
	 * 
	 * @see com.waytojob.teaching.jdbc.IStudentDelegate#addStudent(com.waytojob.teaching.jdbc.Student)
	 */
	public boolean addStudent(Student student)
	{
		if(StudentDelegateImpl.studentDao==null)
		{
			return false;
		}
		try
		{
			StudentDelegateImpl.studentDao.addStudent(student);
			return true;
		}
		catch (SQLException e)
		{
			// TODO 自动生成 catch 块
			e.printStackTrace();
		}
		return false;
	}

	/*
	 * (非 Javadoc)
	 * 
	 * @see com.waytojob.teaching.jdbc.IStudentDelegate#getStudents()
	 */
	public List getStudents()
	{
		if(StudentDelegateImpl.studentDao==null)
		{
			return null;
		}
		try
		{
			return StudentDelegateImpl.studentDao.getStudents();
		}
		catch (SQLException e)
		{
			// TODO 自动生成 catch 块
			e.printStackTrace();
		}
		return null;
	}

}

⌨️ 快捷键说明

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