?? leveldaoimpl.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);
}
}
}
?? 快捷鍵說明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -