?? user_blockdaoimpl.java
字號:
package com.lovo.dao;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import com.lovo.util.DBUtil;
public class User_BlockDAOImpl implements User_BlockDAO {
/**數據庫連接對象*/
private Connection con;
/**預編譯語句對象*/
private PreparedStatement pre;
/**結果集對象*/
private ResultSet rs;
public void insert(int userId, int blockId) throws SQLException {
String sql = "insert into user_block(user_id, block_id) values(?, ?)";
con = DBUtil.getDBUtil().getConnection();
try {
pre = con.prepareStatement(sql);
pre.setInt(1, userId);
pre.setInt(2, blockId);
pre.executeUpdate();
} catch (SQLException e) {
e.printStackTrace();
throw e;
} finally {
DBUtil.getDBUtil().close(rs);
DBUtil.getDBUtil().close(pre);
DBUtil.getDBUtil().close(con);
}
}
public void delete(int userId, int blockId) throws SQLException {
String sql = "delete from user_block where user_id = ? and block_id = ?";
con = DBUtil.getDBUtil().getConnection();
try {
pre = con.prepareStatement(sql);
pre.setInt(1, userId);
pre.setInt(2, blockId);
pre.executeUpdate();
} catch (SQLException e) {
e.printStackTrace();
throw e;
} finally {
DBUtil.getDBUtil().close(rs);
DBUtil.getDBUtil().close(pre);
DBUtil.getDBUtil().close(con);
}
}
public int queryBlockIdBy(int userId) throws SQLException {
String sql = "select block_id from user_block where user_id = ?";
con = DBUtil.getDBUtil().getConnection();
int blockId = 0;
try {
pre = con.prepareStatement(sql);
pre.setInt(1, userId);
rs = pre.executeQuery();
while(rs.next()) {
blockId = rs.getInt("block_id");
}
} catch (SQLException e) {
e.printStackTrace();
throw e;
} finally {
DBUtil.getDBUtil().close(rs);
DBUtil.getDBUtil().close(pre);
DBUtil.getDBUtil().close(con);
}
return blockId;
}
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -