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

📄 leveldaoimpl.java

📁 一个bbs论坛系统
💻 JAVA
字号:
package com.lovo.dao;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;

import com.lovo.po.ImgPO;
import com.lovo.po.LevelPO;
import com.lovo.util.DBUtil;

public class LevelDAOImpl implements LevelDAO {
	private Connection con = null;

	private PreparedStatement st = null;

	private ResultSet rs = null;

	public LevelPO queryLevelById(int levelNum) throws SQLException {

		String sql = "select * from level where levelNum = ?";
		LevelPO level = null;
		try {
			con = DBUtil.getDBUtil().getConnection();
			st = con.prepareStatement(sql);
			st.setInt(1, levelNum);
			rs = st.executeQuery();
			while (rs.next()) {
				level = new LevelPO();
				level.setId(rs.getInt("id"));
				level.setName(rs.getString("name"));
				level.setLevelNum(rs.getInt("levelNum"));
			}
		} catch (SQLException e) {
			e.printStackTrace();
			throw e;
		} finally {
			DBUtil.getDBUtil().close(rs);
			DBUtil.getDBUtil().close(st);
			DBUtil.getDBUtil().close(con);
		}
		return level;
	}

	public void insert(String levelName, int levelNum) throws SQLException {
		String sql = "insert into level(name, levelNum) values(?, ?)";
		con = DBUtil.getDBUtil().getConnection();
		
		try {
			st = con.prepareStatement(sql);
			st.setString(1, levelName);
			st.setInt(2, levelNum);
			st.executeUpdate();
		} catch(SQLException e) {
			e.printStackTrace();
			throw e;
		}  finally {
			DBUtil.getDBUtil().close(rs);
			DBUtil.getDBUtil().close(st);
			DBUtil.getDBUtil().close(con);
		}
		
	}

}

⌨️ 快捷键说明

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