package com.blog.struts.action;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.Statement;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Collection;
import com.blog.struts.form.Liuyan;
import com.blog.struts.form.Pinglun;
import com.blog.struts.form.Reader;
import com.blog.struts.form.Userperson;
import com.blog.util.DBConn;
public class BlogBean {
private Connection conn ;
public BlogBean()throws Exception
{
this.conn=DBConn.getConnection();
}
/**
*在数据库中添加一个用户
*/
public void addReader(Reader reader)throws Exception
{ java.util.Date date= new java.util.Date();
SimpleDateFormat myform=new SimpleDateFormat("yyyy-MM-dd hh:mm:ss");
String mydate=myform.format(date);
Statement stmt=conn.createStatement();
stmt.executeUpdate("insert into reader values('"+reader.getTitle()+"','"+reader.getContent()+"','"+reader.getFenlei()+"','"+mydate+"')");
}
public void addLiuyan(Liuyan liuyan)throws Exception
{ java.util.Date date= new java.util.Date();
SimpleDateFormat myform=new SimpleDateFormat("yyyy-MM-dd hh:mm:ss");
String mydate=myform.format(date);
Statement stmt=conn.createStatement();
stmt.executeUpdate("insert into liuyan values('"+liuyan.getUsername()+"','"+liuyan.getReply_content()+"','"+mydate+"')");
}
public void addUserperson(Userperson userperson)throws Exception
{
Statement stmt=conn.createStatement();
stmt.executeUpdate("insert into userperson values('"+userperson.getUsername()+"','"+userperson.getPassword()+"','"+userperson.getEmail()+"','"+userperson.getBirthday()+"','"+userperson.getArea()+"')");
}
public Userperson getUserperson(String username)throws Exception
{
return this.getStudentHelper1("select * from userperson where username='"+username+"'");
}
public String getUserperson2(String username)throws Exception
{
return this.getStudentHelper2("select * from userperson where username='"+username+"'");
}
public void addPinglun(Pinglun pinglun)throws Exception{
java.util.Date time= new java.util.Date();
SimpleDateFormat myform=new SimpleDateFormat("yyyy-MM-dd hh:mm:ss");
String mydate=myform.format(time);
Statement stmt=conn.createStatement();
stmt.executeUpdate("insert into pinglun values("+pinglun.getId()+",'"+pinglun.getUsername()+"','"+pinglun.getContect()+"','"+mydate+"','"+pinglun.getTitle()+"')");
}
public Collection getReaders()throws Exception
{
return this.getStudentHelper("select * from reader order by date desc");
}
public Collection getRizhi(String rizhi)throws Exception
{
return this.getStudentHelper("select * from reader where rizhi='"+rizhi+"' order by date desc");
}
public Collection getReaderer()throws Exception
{
return this.getReaderHelper("select top 6 title, date from reader order by date desc");
}
public Collection getReader()throws Exception
{
return this.getStudentHelper("select * from reader");
}
/*public Collection getReader(String title)throws Exception{
Statement stmt=conn.createStatement();
ResultSet rst=stmt.executeQuery("select * from reader where title='"+title+"'");
Collection ret=new ArrayList();
while(rst.next())
{
Product temp=new Product();
temp.setProductId(rst.getString("productid"));
temp.setCategoryId(rst.getString("category"));
temp.setName(rst.getString("name"));
temp.setProducer(rst.getString("producer"));
temp.setPrice(rst.getFloat("price"));
temp.setDescription(rst.getString("descn"));
ret.add(temp);
}
con.close();
return ret;
}*/
public int getAvailableCount2(String fenlei)throws Exception
{
int ret=0;
Statement stmt=conn.createStatement();
String strSql="select count(*) from reader where fenlei='"+fenlei+"'";
ResultSet rset=stmt.executeQuery(strSql);
while(rset.next())
{
ret=rset.getInt(1);
}
return ret;
}
public int getAvailableCount1(int id)throws Exception
{
int ret=0;
Statement stmt=conn.createStatement();
String strSql="select count(*) from pinglun where id="+id;
ResultSet rset=stmt.executeQuery(strSql);
while(rset.next())
{
ret=rset.getInt(1);
}
return ret;
}
public int getAvailableCount3()throws Exception
{
int ret=0;
Statement stmt=conn.createStatement();
String strSql="select count(*) from liuyan";
ResultSet rset=stmt.executeQuery(strSql);
while(rset.next())
{
ret=rset.getInt(1);
}
return ret;
}
public int getAvailableCount4()throws Exception
{
int ret=0;
Statement stmt=conn.createStatement();
String strSql="select count(*) from pinglin";
ResultSet rset=stmt.executeQuery(strSql);
while(rset.next())
{
ret=rset.getInt(1);
}
return ret;
}
public int getAvailableCount()throws Exception
{
int ret=0;
Statement stmt=conn.createStatement();
String strSql="select count(*) from reader";
ResultSet rset=stmt.executeQuery(strSql);
while(rset.next())
{
ret=rset.getInt(1);
}
return ret;
}
public void deleteReaderFromDept(int id)throws Exception
{
try
{
this.executeHelper("delete from reader where id="+id);
}
catch(Exception e)
{
e.printStackTrace();
throw e;
}
}
public void deletePinglunFromDept(String time)throws Exception
{
try
{
this.executeHelper("delete from pinglun where time='"+time+"'");
}
catch(Exception e)
{
e.printStackTrace();
throw e;
}
}
public void deletePinglun2FromDept(int id)throws Exception
{
try
{
this.executeHelper("delete from pinglun where id="+id);
}
catch(Exception e)
{
e.printStackTrace();
throw e;
}
}
public Collection listData2(String page,int rowsPerPage)throws Exception
{
try
{
int pageNum=Integer.parseInt(page);
Statement stmt=conn.createStatement();
String strSql="select top "+pageNum*rowsPerPage+" * from reader order by date desc";
ResultSet rst=stmt.executeQuery(strSql);
Collection ret=new ArrayList();
int i=0;
while(rst.next())
{
if(i>(pageNum-1)*rowsPerPage-1)
{
Reader temp=new Reader();
temp.setId(rst.getInt("id"));
temp.setTitle(rst.getString("title"));
temp.setContent(rst.getString("content"));
temp.setFenlei(rst.getString("fenlei"));
temp.setDate(rst.getString("date"));
ret.add(temp);
}
i++;
}
return ret;
}
catch(Exception e)
{
e.printStackTrace();
throw e;
}
}
public Collection listData3(String page,int rowsPerPage)throws Exception
{
try
{
int pageNum=Integer.parseInt(page);
Statement stmt=conn.createStatement();
String strSql="select top "+pageNum*rowsPerPage+" * from liuyan order by times desc";
ResultSet rst=stmt.executeQuery(strSql);
Collection ret=new ArrayList();
int i=0;
while(rst.next())
{
if(i>(pageNum-1)*rowsPerPage-1)
{
Liuyan temp=new Liuyan();
temp.setUsername(rst.getString("username"));
temp.setReply_content(rst.getString("reply_content"));
temp.setTimes(rst.getString("times"));
ret.add(temp);
}
i++;
}
return ret;
}
catch(Exception e)
{
e.printStackTrace();
throw e;
}
}
public void resetReader(Reader reader)throws Exception
{
java.util.Date time= new java.util.Date();
SimpleDateFormat myform=new SimpleDateFormat("yyyy-MM-dd hh:mm:ss");
String mydate=myform.format(time);
PreparedStatement pstmt=conn.prepareStatement("update reader set title=?,content=?,fenlei=?,date=
没有合适的资源?快使用搜索试试~ 我知道了~
资源推荐
资源详情
资源评论
收起资源包目录
blog.rar (98个子文件)
Liublog
liuhuirong_Data.MDF 1024KB
.mystrutsdata 255B
src
com
blog
util
DBConn.java 659B
struts
ApplicationResources.properties 83B
form
AddmanForm.java 2KB
Userperson.java 825B
Pinglun.java 772B
Liuyan.java 559B
AddLiuyanForm.java 2KB
AddrijiForm.java 2KB
Reader.java 747B
action
ShowzijiAction.java 2KB
Show_doAction.java 2KB
BlogBean.java 11KB
Pagin.java 3KB
EncodingFilter.java 2KB
Pagination.java 3KB
ShowallAction.java 2KB
ShowServlet.java 2KB
AddrijiAction.java 1KB
AddLiuyanAction.java 2KB
AddmanAction.java 2KB
ContactServlet.java 2KB
ShowliuyanAction.java 2KB
liuhuirong_Log.LDF 1024KB
.project 1KB
WebRoot
login3.jsp 4KB
META-INF
MANIFEST.MF 39B
showall.jsp 4KB
successes.jsp 2KB
WEB-INF
struts-nested.tld 63KB
struts-template.tld 2KB
validator-rules.xml 41KB
struts-bean.tld 9KB
struts-html.tld 65KB
struts-logic.tld 14KB
struts-tiles.tld 8KB
web.xml 2KB
.struts-config.mex 4KB
classes
com
blog
util
DBConn.class 1KB
struts
ApplicationResources.properties 83B
form
Reader.class 1KB
Pinglun.class 1KB
Userperson.class 1KB
AddmanForm.class 2KB
Liuyan.class 941B
AddLiuyanForm.class 2KB
AddrijiForm.class 2KB
action
ShowServlet.class 2KB
AddLiuyanAction.class 2KB
Pagination.class 2KB
ShowzijiAction.class 3KB
Pagin.class 2KB
ContactServlet.class 3KB
AddmanAction.class 2KB
BlogBean.class 10KB
Show_doAction.class 2KB
AddrijiAction.class 2KB
ShowallAction.class 3KB
ShowliuyanAction.class 2KB
EncodingFilter.class 2KB
struts-config.xml 2KB
lib
struts-legacy.jar 9KB
commons-beanutils.jar 100KB
commons-collections.jar 160KB
jakarta-oro.jar 62KB
commons-validator.jar 40KB
commons-fileupload.jar 19KB
commons-logging.jar 27KB
struts.jar 428KB
commons-digester.jar 96KB
commons-lang.jar 53KB
successel.jsp 989B
login2.jsp 4KB
login_do2.jsp 2KB
pinglun.jsp 1KB
addLiuyan.jsp 8KB
_notes
dwsync.xml 2KB
login_do.jsp 2KB
addriji.jsp 4KB
modify.jsp 5KB
login.jsp 4KB
images.file
01.jpg 75KB
_notes
dwsync.xml 608B
bottom.gif 999B
top.gif 74KB
bg.gif 302B
Thumbs.db 11KB
index.jsp 3KB
addman.jsp 7KB
modify_do.jsp 908B
showriji.jsp 4KB
shanchu.jsp 801B
login_do3.jsp 2KB
success.jsp 1KB
show_do.jsp 9KB
.mymetadata 294B
.classpath 1KB
.myeclipse
共 98 条
- 1
资源评论
JonSco
- 粉丝: 66
- 资源: 1万+
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功