📄 user_areadaoimpl.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_AreaDAOImpl implements User_AreaDAO {
/**数据库连接对象*/
private Connection con;
/**预编译语句对象*/
private PreparedStatement pre;
/**结果集对象*/
private ResultSet rs;
public void insert(int userId, int areaId) throws SQLException {
String sql = "insert into user_area(user_id, area_id) values(?, ?)";
con = DBUtil.getDBUtil().getConnection();
try {
pre = con.prepareStatement(sql);
pre.setInt(1, userId);
pre.setInt(2, areaId);
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 areaId) throws SQLException {
String sql = "delete from user_area where user_id = ? and area_id = ?";
con = DBUtil.getDBUtil().getConnection();
try {
pre = con.prepareStatement(sql);
pre.setInt(1, userId);
pre.setInt(2, areaId);
pre.executeUpdate();
} catch (SQLException e) {
e.printStackTrace();
throw e;
} finally {
DBUtil.getDBUtil().close(rs);
DBUtil.getDBUtil().close(pre);
DBUtil.getDBUtil().close(con);
}
}
public int queryAreaIdBy(int userId) throws SQLException {
String sql = "select block_id from user_block where user_id = ?";
con = DBUtil.getDBUtil().getConnection();
int areaId = 0;
try {
pre = con.prepareStatement(sql);
pre.setInt(1, userId);
rs = pre.executeQuery();
while(rs.next()) {
areaId = 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 areaId;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -