资源简介
新闻中心管理系统代码+sql 数据库连接Mysql数据库,在eclipse下完成,只要把数据库连接起来就不会出错
代码片段和文件信息
package lxd.dao;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Timestamp;
import java.util.ArrayList;
import lxd.database.DB;
import lxd.model.News;
public class NewsDAO {
private DB db=new DB();
public static NewsDAO getInstance(){
return new NewsDAO();
}
public void insert(News n) {
try {
Connection con = db.getCon();
String sql = “insert into news(titlecontenttauthornum)“
+ “ values(???10)“;
PreparedStatement ps = con.prepareStatement(sql);
ps.setString(1 n.gettitle());
ps.setString(2 n.getContent());
ps.setTimestamp(3 new Timestamp(n.getT().getTime()));
ps.executeUpdate();
db.close();
} catch (SQLException e) {
e.printStackTrace();
}
}
public ArrayList select(){
ArrayList list=new ArrayList();
try{
Connection con=db.getCon();
String sql=“select * from news order by t desc“;
PreparedStatement ps=con.prepareStatement(sql);
ResultSet rs=ps.executeQuery();
while(rs.next()){
News n=new News();
n.setId(rs.getInt(1));
n.settitle(rs.getString(2));
n.setContent(rs.getString(3));
n.setT(rs.getDate(4));
n.setAuthor(rs.getInt(5));
n.setNum(rs.getInt(6));
list.add(n);
}
db.close();
}catch(Exception e){
System.out.println(e);
}
return list;
}
public News select(int id){
News n=null;
try{
Connection con=db.getCon();
String sql=“select * from news where id=?“;
PreparedStatement ps=con.prepareStatement(sql);
ps.setInt(1 id);
ResultSet rs=ps.executeQuery();
if(rs.next()){
n=new News();
n.setId(rs.getInt(1));
n.settitle(rs.getString(2));
n.setContent(rs.getString(3));
n.setT(rs.getDate(4));
n.setAuthor(rs.getInt(5));
n.setNum(rs.getInt(6));
}
db.close();
}catch(Exception e){
System.out.println(e);
}
return n;
}
public void delete(int id){
try{
Connection con=db.getCon();
String sql=“delete from news where id=?“;
PreparedStatement ps=con.prepareStatement(sql);
ps.setInt(1 id);
ps.executeUpdate();
db.close();
}catch(Exception e){
System.out.println(e);
}
}
public void update(News n){
try{
Connection con=db.getCon();
String sql=“update news set title =? content=?“
+ “ where id=?“;
PreparedStatement ps=con.prepareStatement(sql);
ps.setString(1 n.gettitle());
ps.setString(2 n.getContent());
ps.setInt(3 n.getId());
ps.executeUpdate();
db.close();
}catch(Exception e){
System.out.println(e);
}
}
public void update(int id){
try{
Connection con=db.getCon();
String sql=“update news set num=num+1 where id=?“;
PreparedStatement ps=con.prepareStatement(sql);
ps.setInt(1 id);
ps.executeUpdate();
db.close();
}catch(Exception e){
System.out.println(e)
属性 大小 日期 时间 名称
----------- --------- ---------- ----- ----
....... 834 2015-05-13 14:44 abc\.classpath
....... 1036 2015-05-13 14:44 abc\.project
....... 503 2015-05-13 14:44 abc\.settings\.jsdtscope
....... 364 2015-05-13 14:44 abc\.settings\org.eclipse.jdt.core.prefs
....... 461 2015-05-13 14:44 abc\.settings\org.eclipse.wst.common.component
....... 345 2015-05-13 14:45 abc\.settings\org.eclipse.wst.common.project.facet.core.xm
....... 49 2015-05-13 14:44 abc\.settings\org.eclipse.wst.jsdt.ui.superType.container
....... 6 2015-05-13 14:44 abc\.settings\org.eclipse.wst.jsdt.ui.superType.name
....... 157 2015-05-13 18:00 abc\build\classes\create.sql
....... 4276 2015-05-27 15:11 abc\build\classes\lxd\dao\NewsDAO.class
....... 1453 2015-05-27 15:06 abc\build\classes\lxd\databa
....... 1722 2015-05-27 15:06 abc\build\classes\lxd\model\News.class
....... 1615 2015-05-29 09:02 abc\build\classes\lxd\servlet\ModifyNews.class
....... 1516 2015-05-27 15:06 abc\build\classes\lxd\servlet\NewsServlet.class
....... 364 2015-05-27 15:06 abc\build\classes\lxd\test\T.class
....... 157 2015-05-13 18:00 abc\src\create.sql
....... 3029 2015-05-27 15:11 abc\src\lxd\dao\NewsDAO.java
....... 831 2015-05-13 18:03 abc\src\lxd\databa
....... 1105 2015-05-13 18:08 abc\src\lxd\model\News.java
....... 1510 2015-05-29 09:02 abc\src\lxd\servlet\ModifyNews.java
....... 1030 2015-05-15 08:24 abc\src\lxd\servlet\NewsServlet.java
....... 95 2015-05-13 18:10 abc\src\lxd\test\T.java
....... 3386 2015-05-29 08:14 abc\WebContent\browse.jsp
....... 5567 2015-04-07 14:37 abc\WebContent\css\flexslider.css
....... 2082 2015-04-07 14:37 abc\WebContent\css\fonts\flexslider-icon.eot
....... 2334 2015-04-07 14:37 abc\WebContent\css\fonts\flexslider-icon.svg
....... 1892 2015-04-07 14:37 abc\WebContent\css\fonts\flexslider-icon.ttf
....... 1268 2015-04-07 14:37 abc\WebContent\css\fonts\flexslider-icon.woff
....... 586 2015-05-20 15:03 abc\WebContent\dele.jsp
....... 3064 2015-05-13 15:57 abc\WebContent\images\buttons.gif
............此处省略48个文件信息
- 上一篇:教务系统数据库
- 下一篇:蔬菜水果销售商城--毕设
评论
共有 条评论