资源简介
Servlet增删改查+Mysql+分页,本人刚刚写好的.测试过 可以跑起来所有的功能可以用里面有数据库。带分页 请放心下载。绝对真实
代码片段和文件信息
package biz;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.util.ArrayList;
import java.util.List;
import dao.baseDao;
import entity.Page;
import entity.Pagection;
import entity.User;
public class UserBiz {
Connection con;
PreparedStatement ps;
ResultSet rs;
/**
* 查询所有
*/
public List Userall() {
con = baseDao.Connect();
List list = new ArrayList();
try {
String sql = “select * from user“;
ps = con.prepareStatement(sql);
rs = ps.executeQuery();
while (rs.next()) {
User us = new User();
us.setId(rs.getInt(“id“));
us.setName(rs.getString(“name“));
us.setPwd(rs.getString(“pwd“));
us.setSex(rs.getString(“sex“));
list.add(us);
}
} catch (Exception e) {
e.printStackTrace();
} finally {
baseDao.CloseConnect();
}
return list;
}
/**
* 查询一条数据
*/
public List UpdateUserOne(int id) {
con = baseDao.Connect();
List list = new ArrayList();
try {
String sql = “select * from user where id = “ + id + ““;
ps = con.prepareStatement(sql);
rs = ps.executeQuery();
while (rs.next()) {
User us = new User();
us.setId(rs.getInt(“id“));
us.setName(rs.getString(“name“));
us.setPwd(rs.getString(“pwd“));
us.setSex(rs.getString(“sex“));
list.add(us);
}
} catch (Exception e) {
e.printStackTrace();
} finally {
baseDao.CloseConnect();
}
return list;
}
/**
* 修改
*/
public int UpdateUser(User us) {
int a = 0;
con = baseDao.Connect();
try {
String sql = “update user set name=‘“ + us.getName() + “‘pwd=‘“
+ us.getPwd() + “‘sex=‘“ + us.getSex() + “‘ where id=“
+ us.getId() + ““;
ps = con.prepareStatement(sql);
a = ps.executeUpdate();
} catch (Exception e) {
e.printStackTrace();
} finally {
baseDao.CloseConnect();
}
return a;
}
/**
* 添加
*/
public int AddUser(User us) {
int a = 0;
con = baseDao.Connect();
try {
String sql = “insert into user(namepwdsex) values(‘“+ us.getName() + “‘‘“ + us.getPwd() + “‘‘“ + us.getSex()+ “‘)“;
ps = con.prepareStatement(sql);
a = ps.executeUpdate();
} catch (Exception e) {
e.printStackTrace();
} finally {
baseDao.CloseConnect();
}
return a;
}
/**
* 删除
*/
public int DeleteUser(int id) {
int a = 0;
con = baseDao.Connect();
try {
String sql = “delete from user where id=“ + id + ““;
ps = con.prepareStatement(sql);
a = ps.executeUpdate();
} catch (Exception e) {
e.printStackTrace();
} finally {
baseDao.CloseConnect();
}
return a;
}
/**
* 分页
*/
public Pagection Paging(int pagection) {
Page _p = new Page();
Pagection p = new Pagection();
_p.setCurrent(pagection);
int amount = 0;
con = baseDao.Connect();
String sql = “select count(0) from user“;
try {
ps = con.prepareStatem
属性 大小 日期 时间 名称
----------- --------- ---------- ----- ----
目录 0 2011-10-18 11:52 additions\
文件 851 2011-10-17 17:26 additions\.classpath
文件 444 2011-10-17 15:32 additions\.project
目录 0 2011-10-17 16:59 additions\.settings\
文件 133 2011-10-17 18:09 additions\.settings\org.eclipse.core.resources.prefs
文件 83 2011-10-17 16:59 additions\.settings\org.eclipse.core.runtime.prefs
文件 629 2011-10-17 09:23 additions\.settings\org.eclipse.jdt.core.prefs
文件 366 2011-10-17 17:05 additions\.tomcatplugin
目录 0 2011-10-17 09:30 additions\src\
目录 0 2011-10-17 09:29 additions\src\biz\
文件 3778 2011-10-18 11:26 additions\src\biz\UserBiz.java
目录 0 2011-10-17 09:28 additions\src\dao\
文件 1060 2011-10-17 16:55 additions\src\dao\ba
目录 0 2011-10-17 13:22 additions\src\entity\
文件 1155 2011-10-18 11:50 additions\src\entity\Page.java
文件 347 2011-10-17 16:55 additions\src\entity\Pagection.java
文件 855 2011-10-17 16:55 additions\src\entity\User.java
目录 0 2011-10-17 14:57 additions\src\servlet\
文件 1220 2011-10-18 10:46 additions\src\servlet\AddServlet.java
文件 875 2011-10-17 16:56 additions\src\servlet\AllServlet.java
文件 990 2011-10-18 10:51 additions\src\servlet\DeleteServlet.java
文件 898 2011-10-17 18:08 additions\src\servlet\PageServlet.java
文件 1296 2011-10-18 11:08 additions\src\servlet\UpdateServlet.java
文件 947 2011-10-17 18:10 additions\src\servlet\UpdateServletOne.java
文件 1205 2011-10-14 17:27 additions\user.sql
目录 0 2011-10-17 17:15 additions\WebRoot\
文件 1188 2011-10-17 18:11 additions\WebRoot\add.jsp
文件 2536 2011-10-18 10:49 additions\WebRoot\all.jsp
文件 429 2011-10-17 17:08 additions\WebRoot\list.jsp
目录 0 2011-10-17 16:39 additions\WebRoot\me
文件 39 2008-05-31 18:14 additions\WebRoot\me
............此处省略51个文件信息
- 上一篇:SQL学生成绩管理系统
- 下一篇:sql server 2005 完整版
评论
共有 条评论