package com.blog.dao;
import java.sql.*;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;
import com.blog.obj.Novel;
import dbconn.DBConn;
public class NovelDao{
int flag=0;
/**
* 添加一条博文记录
* @param notice
* @return 标识flag
*/
public int novelAdd(Novel novel){
DBConn db=new DBConn();
String sql="insert novel(name,kindid,kindname,content,submittime,click_num,comment_num)values('"+novel.getNovelName()+"','"+novel.getKindId()+"','"+novel.getKindName()+"','"+novel.getContent()+"','"+novel.getSubmittime()+"','"+novel.getClick_num()+"','"+novel.getComment_num()+"')";
db.getConn();
flag=db.executeUpdate(sql);
return flag;
}
/**
* 查询所有博文记录
* @return 记录集合list
*/
public List<Novel> getNovel(){
List<Novel> list = new ArrayList<Novel>();
DBConn db= new DBConn();
ResultSet rs= null;
try{
String sql;
sql="select * from novel";
db.getConn();
rs=db.executeQuery(sql);
while(rs.next()){
Novel novel=new Novel();
novel.setId(rs.getInt(1));
novel.setNovelName(rs.getString(2));
novel.setKindId(rs.getString(3));
novel.setKindName(rs.getString(4));
novel.setSubmittime(rs.getString(6));
novel.setClick_num(rs.getInt(7));
novel.setComment_num(rs.getInt(8));
list.add(novel);
}
return list;
}catch(SQLException e){
e.printStackTrace();
}
return list;
}
/**
* 删除一条博文记录
* @param id
* @return 标识flag
*/
public int novelDelete(String id){
DBConn db= new DBConn();
db.getConn();
int idnum=0;
if(("".equals(id))&&(id!=null)){
idnum=Integer.getInteger(id);
}
String sql="delete novel where id="+idnum;
flag=db.executeUpdate(sql);
return flag;
}
/**
* 查询一条博文记录
* @param id
* @return
*/
public Novel novelSone(int id){
Novel novel=new Novel();
DBConn db= new DBConn();
ResultSet rs=null;
try{
db.getConn();
String sql="select * from novel where id='"+id+"'";
rs=db.executeQuery(sql);
if(rs.next()){
novel.setId(rs.getInt(1));
novel.setNovelName(rs.getString(2));
novel.setKindId(rs.getString(3));
novel.setKindName(rs.getString(4));
novel.setContent(rs.getString(5));
}
}catch(SQLException e){
e.printStackTrace();
}
return novel;
}
/**
* 更新一条博文记录
* @param id
* @return
*/
public int novelUpdate(String name,String content,String time,int id){
DBConn db= new DBConn();
db.getConn();
String sql;
sql="update novel set name='"+name+"' , content='"+content+"',submittime='"+time+"'where id='"+id+"'";
flag=db.executeUpdate(sql);
return flag;
}
/**
* 更新博文点击次数
* @return
*/
public int novelClick(int id,int click_num) {
DBConn db= new DBConn();
db.getConn();
String sql = "update novel set click_num='"+click_num+"' where id='"+id+"'";
flag=db.executeUpdate(sql);
//System.out.print(flag);
return flag;
}
/**
* 更新博文评论数
* @return
*/
public void novelComment(int id,int comment_num) {
DBConn db= new DBConn();
db.getConn();
String sql = "update novel set comment_num='"+comment_num+"' where id='"+id+"'";
flag = db.executeUpdate(sql);
}
}
- 1
- 2
前往页