📄 dbboardfactory.java
字号:
catch (Exception ex) {
logger.error("showBoaInfo 关闭数据库连接失败 error : " + ex.getMessage());
}
}
return board;
}
/**
* show 模板信息
* @return String
*/
public Collection showBoaInfo() {
Connection conn = DBConnectionManager.getInstance().getConnection(
);
Statement stmt = null;
ArrayList arrayList = new ArrayList();
ResultSet rs = null;
try {
stmt = conn.createStatement();
rs = stmt.executeQuery(SHOW_BOARDINFO);
while (rs.next()) {
DBBoard board = new DBBoard();
board.setBoaId(rs.getInt("boaId"));
board.setBoaType(rs.getString("boaType"));
board.setBoaParId(rs.getInt("boaParId"));
board.setBoaDepth(rs.getInt("boaDepth"));
board.setBoaRootId(rs.getInt("boaRootId"));
board.setBoaChild(rs.getInt("boaChild"));
board.setBoaMaster(rs.getString("boaMaster"));
arrayList.add(board);
}
}
catch (Exception ex) {
logger.error("显示模板信息失败 : " + ex.getMessage());
}
finally {
try {
rs.close();
}
catch (Exception ex) {
logger.info("关闭指针失败 error : " + ex.getMessage());
}
try {
stmt.close();
}
catch (Exception ex) {
logger.error("关闭 pstm 失败 error : " + ex.getMessage());
}
try {
conn.close();
}
catch (Exception ex) {
logger.error("关闭数据库连接失败 error : " + ex.getMessage());
}
}
return arrayList;
}
/**
* 设置初始的boardID的值
*/
public String getMaxBoardId() {
String boaId = null;
Connection conn = DBConnectionManager.getInstance().getConnection(
);
Statement stmt = null;
ResultSet rs = null;
try {
stmt = conn.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE,
ResultSet.CONCUR_READ_ONLY);
rs = stmt.executeQuery(MAX_BOARDID);
rs.next();
boaId = rs.getString(1);
if (boaId == null) {
boaId = "1";
}
else {
boaId = String.valueOf(Integer.parseInt(boaId) + 1);
logger.info("初始模板的值为 : " + boaId);
}
}
catch (Exception ex) {
logger.error("获取模板ID出错 : " + ex.getMessage());
}
finally {
try {
rs.close();
}
catch (Exception ex) {
logger.info("关闭指针失败 error : " + ex.getMessage());
}
try {
stmt.close();
}
catch (Exception ex) {
logger.error("关闭 pstm 失败 error : " + ex.getMessage());
}
try {
conn.close();
}
catch (Exception ex) {
logger.error("关闭数据库连接失败 error : " + ex.getMessage());
}
}
return boaId;
}
/**
* 设置初始的rootId的值
* @return String
*/
public int getMaxRootId() {
int boaRootId = 0;
Connection conn = DBConnectionManager.getInstance().getConnection(
);
Statement stmt = null;
ResultSet rs = null;
try {
stmt = conn.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE,
ResultSet.CONCUR_READ_ONLY);
rs = stmt.executeQuery(MAX_ROOTID);
rs.next();
boaRootId = rs.getInt(1);
if (boaRootId == 0) {
boaRootId = 1;
}
else {
boaRootId = boaRootId + 1;
logger.info("初始rootId的值为 : " + boaRootId);
}
}
catch (Exception ex) {
logger.error("获取模板ID出错 : " + ex.getMessage());
}
finally {
try {
rs.close();
}
catch (Exception ex) {
logger.info("关闭指针失败 error : " + ex.getMessage());
}
try {
stmt.close();
}
catch (Exception ex) {
logger.error("关闭 pstm 失败 error : " + ex.getMessage());
}
try {
conn.close();
}
catch (Exception ex) {
logger.error("关闭数据库连接失败 error : " + ex.getMessage());
}
}
return boaRootId;
}
/**
* 更新子节点
*/
public void upChildId(int boaId) {
Connection conn = DBConnectionManager.getInstance().getConnection(
);
PreparedStatement pstm = null;
ResultSet rs = null;
try {
pstm = conn.prepareStatement(UPDATE_BOARD_CHILDID);
pstm.setInt(1, boaId);
pstm.executeUpdate();
logger.info("成功更新子节点");
}
catch (Exception ex) {
logger.error("获取模板ID出错 : " + ex.getMessage());
}
finally {
try {
pstm.close();
}
catch (Exception ex) {
logger.error("关闭 pstm 失败 error : " + ex.getMessage());
}
try {
conn.close();
}
catch (Exception ex) {
logger.error("关闭数据库连接失败 error : " + ex.getMessage());
}
}
}
/**
* 递归调用(更新子节点)
* @param board Board
* @return boolean
*/
public int getParId(int childId) {
Connection conn = DBConnectionManager.getInstance().getConnection(
);
PreparedStatement pstm = null;
ResultSet rs = null;
int parId = 0;
try {
pstm = conn.prepareStatement(SELECT_PARENDID);
pstm.setInt(1, childId);
rs = pstm.executeQuery();
if (rs.next()) {
parId = rs.getInt("boaParId");
logger.info("父节点的值为 : " + parId);
}
}
catch (Exception ex) {
logger.info("检索数据发生错误 :" + ex.getMessage());
}
finally {
try {
rs.close();
}
catch (Exception ex) {
logger.error("关闭 指针 失败 error : " + ex.getMessage());
}
try {
pstm.close();
}
catch (Exception ex) {
logger.error("关闭 pstm 失败 error : " + ex.getMessage());
}
try {
conn.close();
}
catch (Exception ex) {
logger.error("关闭数据库连接失败 error : " + ex.getMessage());
}
}
return parId;
}
public boolean insBoard(Board board) {
boolean isSuccess = false;
Connection conn = DBConnectionManager.getInstance().getConnection(
);
PreparedStatement pstm = null;
Timer timer = new TimerExpress("yyyy-MM-dd HH:mm:ss");
//从选择列表获取的值
int boaParId = board.getBoaParId();
//变量
String boaParENUM = "0";
int boaDepth = 0;
int boaRootId = 0;
int boaChild = 0;
int boaOrders = 0;
/**
* 当boaParId不为0时候(有父节点)
*/
if (boaParId != 0) {
//parId不为 0 创建子类情况
ResultSet rs = null;
try {
pstm = conn.prepareStatement(SELECT_BOARD);
pstm.setInt(1, boaParId);
rs = pstm.executeQuery();
rs.next();
boaParENUM = rs.getString("boaParENUM");
logger.info("boaParENUM的值为 : " + boaParENUM);
boaDepth = rs.getInt("boaDepth");
logger.info("该节点的深度 : " + boaDepth);
boaRootId = rs.getInt("boaRootId");
logger.info("root节点为 : " + rs.getInt("boaRootId"));
boaChild = rs.getInt("boaChild");
//boaOrders = rs.getInt("boaOrders");
}
catch (Exception ex) {
logger.info("获取选择电台数据 error :" + ex.getMessage());
}
finally {
try {
rs.close();
}
catch (Exception ex) {
logger.error("关闭 rs 失败 error : " + ex.getMessage());
}
try {
pstm.close();
}
catch (Exception ex) {
logger.error("关闭 pstm 失败 error : " + ex.getMessage());
}
}
}
try {
pstm = conn.prepareStatement(INSERT_BOARD);
pstm.setInt(1, board.getBoaId());
pstm.setString(2, board.getBoaType());
pstm.setInt(3, boaParId);
if (boaParId == 0) {
pstm.setString(4, "0");
pstm.setInt(5, 0);
pstm.setInt(6, getMaxRootId());
//pstm.setInt(7,0);
pstm.setInt(7, 0);
}
else {
//如果取得boaParENUM的值为 "0":代表boaParENUM是大模板
logger.info(String.valueOf("0".equals(boaParENUM)));
if (! ("0".equals(boaParENUM))) {
//不等于"0",就加上分格符
boaParENUM = boaParENUM + "," + String.valueOf(boaParId);
}
else {
boaParENUM = String.valueOf(boaParId);
}
pstm.setString(4, boaParENUM);
pstm.setInt(5, boaDepth + 1);
logger.info("帖子深度为 : " + (boaDepth));
pstm.setInt(6, boaRootId);
/**
* 设置childId的值
*/
logger.info("子节点设置.....");
setChildId(boaParId, boaDepth + 1);
//pstm.setInt(7,0);
pstm.setInt(7, board.getBoaId());
}
pstm.setString(8, board.getBoaInfo());
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -