📄 categoryop.java
字号:
package huc.blog.op;
import huc.blog.bean.Blog;
import huc.blog.bean.Category;
import huc.blog.util.DateUtils;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;
public class CategoryOp extends BaseOp {
public List getCategoryList(String userid){
conn = db.getConnection();
List result = new ArrayList();
try {
StringBuffer sql = new StringBuffer();
sql.append("select * from H_CATEGORY where userid = ?");
pst = conn.prepareStatement(sql.toString());
pst.setString(1, userid);
rs = pst.executeQuery();
while(rs.next()){
Category category = new Category();
category.setId(rs.getString("id"));
category.setCategoryName(rs.getString("categoryName"));
category.setUserid(rs.getString("userid"));
result.add(category);
}
} catch (SQLException e) {
e.printStackTrace();
return new ArrayList();
}
finally{
close();
}
return result;
}
/**
* 添加新的类别
* @param category
* @return
*/
public Category add(Category category){
conn = db.getConnection();
try {
StringBuffer sql = new StringBuffer();
sql.append("insert into H_CATEGORY(");
sql.append("userid,categoryName) ");
sql.append(" values(?,?)");
pst = conn.prepareStatement(sql.toString());
pst.setString(1, category.getUserid());
pst.setString(2, category.getCategoryName());
int line = pst.executeUpdate();
if(line == 1){
sql.delete(0, sql.length());
sql.append("select id from H_CATEGORY where userid=? and categoryName=?");
pst = conn.prepareStatement(sql.toString());
pst.setString(1, category.getUserid());
pst.setString(2, category.getCategoryName());
rs = pst.executeQuery();
rs.next();
category.setId(rs.getString("id"));
}
else
category = null;
} catch (SQLException e) {
e.printStackTrace();
return null;
}
finally{
close();
}
return category;
}
/**
* 检查该类别是否已存在
* @param category
* @return
*/
public boolean checkCategory(Category category){
boolean flag = false;
conn = db.getConnection();
try {
StringBuffer sql = new StringBuffer();
sql.append("select id from H_CATEGORY where userid=? and categoryName=?");
pst = conn.prepareStatement(sql.toString());
pst.setString(1, category.getUserid());
pst.setString(2, category.getCategoryName());
rs = pst.executeQuery();
if(rs.next())
flag = true;
} catch (SQLException e) {
e.printStackTrace();
return flag;
}
finally{
close();
}
return flag;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -