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

📄 themedaoimpl.java

📁 出试卷系统(包括前台教师出卷系统
💻 JAVA
字号:
package daoImpl;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.Collection;
import org.springframework.orm.hibernate3.support.HibernateDaoSupport;

import util.JdbcUtil;
import dao.ThemeDAO;
import entity.Theme;

public class ThemeDAOImpl extends HibernateDaoSupport implements ThemeDAO{

	public Collection<Theme> listTheme() {
		String hql = "from Theme t";
			return this.getHibernateTemplate().find(hql);
	
	
	}

	public void saveandupdate(Theme theme) {
		System.out.println("dao****88"+theme);
		System.out.println(theme);
		this.getHibernateTemplate().saveOrUpdate(theme);
		
	}

	public Theme getThemeById(Long id) {
		Theme instance = (Theme) getHibernateTemplate().get(
				"entity.Theme", id);
		return instance;
	}

	public void delete(Theme theme) {
		// TODO Auto-generated method stub
		this.getHibernateTemplate().delete(theme);
	}
	public Theme selectById(int id) {
		Theme theme = new Theme();
		Connection con = null;
		PreparedStatement ps = null;
		ResultSet rs = null;
		String sql = "select * from t_theme where id=? order by id";
		try {
			con = JdbcUtil.getConnection();
			ps = con.prepareStatement(sql);
			ps.setInt(1, id);
			rs = ps.executeQuery();
			while (rs.next()) {
				theme.setId(rs.getInt(1));
				theme.setName(rs.getString(2));
			}
		} catch (SQLException e) {
			e.printStackTrace();
			if (con != null) {
				try {
					con.rollback();
				} catch (SQLException e1) {
					e1.printStackTrace();
				}
			}
		} finally {
			JdbcUtil.release(rs, ps, con);
		}
		return theme;
	}
}

⌨️ 快捷键说明

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