package com.dao;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;
import com.vo.Products;
public class Dao {
private Connection connection=null;
public Dao() {
connection=DBhandler.getConnection();
}
//增加
public void add(Products product) throws Exception{
String sql = "insert into products values(?,?,?,?,?)";
PreparedStatement statement = connection.prepareStatement(sql);
statement.setString(1, product.getId());
statement.setString(2, product.getName());
statement.setFloat(3, product.getPrice());
statement.setString(4, product.getCategory());
statement.setInt(5, product.getNumber());
statement.executeUpdate();
statement.close();
}
//查找编号
public List<Products> finddeptid(String type) throws SQLException{
List<Products> products=new ArrayList<Products>();
if(connection!=null && !connection.isClosed()){
String sql="select id,name,price,category,number from products where category='"+type+"'";
PreparedStatement ps=(PreparedStatement) connection.prepareStatement(sql);
ResultSet rs=ps.executeQuery();
while(rs.next()){
products.add(new Products(rs.getString(1),rs.getString(2),rs.getFloat(3),rs.getString(4),rs.getInt(5)));
}
rs.close();
ps.close();
}
return products;
}
//查询单个
public Products getProductById(String id) throws Exception{
Products products = new Products();
String sql = "select id,name,price,category,number from products where id=?";
PreparedStatement statement = connection.prepareStatement(sql);
statement.setString(1, id);
ResultSet set = statement.executeQuery();
if(set.next()){
products=new Products(set.getString(1),set.getString(2),set.getFloat(3),set.getString(4),set.getInt(5));
}
set.close();
statement.close();
return products;
}
//查询
public List<Products> getAll() throws Exception{
List<Products> products = new ArrayList<Products>();
String sql = "select id,name,price,category,number from products";
PreparedStatement statement = connection.prepareStatement(sql);
ResultSet set = statement.executeQuery();
while(set.next()){
products.add(new Products(set.getString(1),set.getString(2),set.getFloat(3),set.getString(4),set.getInt(5)));
}
set.close();
statement.close();
return products;
}
//修改信息
public void updata(String pid,Products product) throws SQLException{
if(connection!=null &&!connection.isClosed()){
String sql="update products set id=?,name=?,price=?,category=?,number=? where id=?";
PreparedStatement ps=(PreparedStatement) connection.prepareStatement(sql);
ps.setString(1, product.getId());
ps.setString(2, product.getName());
ps.setFloat(3, product.getPrice());
ps.setString(4, product.getCategory());
ps.setInt(5, product.getNumber());
ps.setString(6, pid);
int n=ps.executeUpdate();
System.out.println("更新:"+n);
ps.close();
}
}
//删除
public void delete(String n) throws SQLException{
if(connection!=null && !connection.isClosed()){
String sql="delete from products where id= ?";
PreparedStatement ps=(PreparedStatement) connection.prepareStatement(sql);
ps.setString(1, n);
ps.executeUpdate();
ps.close();
}
}
//关闭连接的方法
public void close() throws Exception{
connection.close();
}
/*public static void main(String[] args) throws Exception {
List<Products> list = new Dao().getAll();
System.out.println(list.size());
}*/
}
没有合适的资源?快使用搜索试试~ 我知道了~
基于struts2商品管理项目
共90个文件
class:20个
java:20个
jsp:15个
3星 · 超过75%的资源 需积分: 12 26 下载量 36 浏览量
2013-03-26
13:19:12
上传
评论 1
收藏 11.09MB RAR 举报
温馨提示
管理员进行注册登录,登录后对商品进行增加分类,修改,删除,查询。用户登录进行浏览查询,评论与投票。
资源推荐
资源详情
资源评论
收起资源包目录
struts2_14_lianxi.rar (90个子文件)
struts2_14_lianxi
.project 1KB
.mymetadata 324B
src
Vote.java 507B
struts.xml 2KB
suggest.sql 196B
db.sql 232B
com
action
VoteAction.java 2KB
AddAction.java 920B
UserAction.java 563B
ShowAction.java 2KB
UpdateAction.java 700B
KindShowAction.java 809B
CompartorAction.java 814B
SelectAllAction.java 2KB
SendAction.java 2KB
DeleteAction.java 479B
SuggestAction.java 906B
RegisterAction.java 2KB
dao
Dao.java 4KB
DBhandler.java 951B
SuggestDao.java 1KB
vo
User.java 782B
Vote.java 522B
Suggest.java 1KB
Products.java 1KB
vote.sql 110B
WebRoot
show.jsp 1KB
WEB-INF
classes
Vote.class 1009B
struts.xml 2KB
suggest.sql 196B
db.sql 232B
com
action
AddAction.class 2KB
CompartorAction.class 2KB
UpdateAction.class 1KB
DeleteAction.class 905B
SuggestAction.class 1KB
SendAction.class 3KB
UserAction.class 1KB
VoteAction.class 2KB
RegisterAction.class 3KB
KindShowAction.class 2KB
ShowAction.class 3KB
SelectAllAction.class 2KB
dao
SuggestDao.class 2KB
DBhandler.class 1KB
Dao.class 4KB
vo
User.class 1KB
Vote.class 1023B
Suggest.class 2KB
Products.class 2KB
vote.sql 110B
lib
poi-3.6-20091214.jar 1.47MB
poi-ooxml-schemas-3.6-20091214.jar 3.6MB
poi-ooxml-3.6-20091214.jar 403KB
dom4j-1.6.1.jar 307KB
mysql-connector-java-5.0.0-beta-bin.jar 464KB
xwork-core-2.1.6.jar 1.49MB
freemarker-2.3.15.jar 859KB
struts2-core-2.1.8.1.jar 738KB
struts2-jquery-plugin-1.8.3.jar 713KB
commons-io-1.3.2.jar 86KB
commons-fileupload-1.2.1.jar 56KB
ognl-2.7.3.jar 234KB
web.xml 704B
vote.jsp 615B
result.jsp 2KB
index1.jsp 1KB
index.jsp 1KB
welcome.jsp 276B
suggest.jsp 1KB
index5.jsp 1KB
UserShowInfo.jsp 2KB
ShowInfo.jsp 2KB
update.jsp 1KB
META-INF
MANIFEST.MF 39B
login.jsp 633B
image
2.jpg 189KB
2.gif 6KB
1.jpg 310KB
26.jpg 225KB
25.jpg 584KB
a.jpg 98KB
24.jpg 97KB
10.jpg 481KB
27.jpg 123KB
3.jpg 357KB
deletesuccess.jsp 726B
index4.jsp 710B
index2.jsp 1KB
.myeclipse
.classpath 1KB
共 90 条
- 1
资源评论
- zxf07962013-05-03说句实话,不怎么好
- u0106452782014-08-06资源还是不错的哦
- bravly_kiss2013-04-10部署可以使用,适合初学者
homeworkhappy
- 粉丝: 2
- 资源: 3
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
最新资源
- 基于ThinkPHP的轻量级PHP开发框架设计源码
- 基于CSS的响应式鲜花网站全屏效果设计源码
- 基于JavaScript的访客预约系统设计源码
- 基于Vue和ECharts的工作租房数据可视化系统设计源码
- 1040g0cg310ravpiu6ibg5pg00tsipsln3ju2d0g 2
- 基于Python的SAR图像去噪CNN-NLM设计源码
- redhat6升级到redhat7,过程redhat6.x-> redhat6.10->rehat7.9 主版本最高版本
- 基于Django的流程引擎设计源码
- 基于Node.js的Express框架与MySQL的后台管理系统设计源码
- 基于Java的Flink流批一体数据处理快速集成开发框架设计源码
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功