package com.DateSystem;
import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.LinkedList;
import java.util.List; import javax.swing.JOptionPane; import com.gui.*;
public class Good_data {
//根据商品名查询
public List<Goods> findGoods(String sql){
List<Goods> list=new LinkedList<Goods>();
Statement stat=null;
ResultSet rs=null; //获取和数据库的连接
Connection conn=ConnectionDriver.getConnection();
try {
//生成Statement对象,封装SQL语句,执行查询
stat=conn.createStatement();
rs=stat.executeQuery(sql);
//处理结果集中数据,读取每一条记录
while(rs.next()){
//int id=rs.getInt(1);
String id=rs.getString(1); String name=rs.getString(2);
String address=rs.getString(3); double in_price=rs.getDouble(4);
double out_price=rs.getDouble(5); int jinhuo=rs.getInt(6);
int chuhuo=rs.getInt(7);
int kucun=rs.getInt(8); Goods d=new Goods(); d.setName(name);
d.setId(id);
d.setAddress(address);
d.setIn_price(in_price);
d.setOut_price(out_price);
d.setKucun(kucun);
d.setJinhuo(jinhuo);
d.setChuhuo(chuhuo);
list.add(d); }
} catch (SQLException e) {
e.printStackTrace();
}finally{
JDBcloss.close(rs, stat, conn);
} return list;
}
//依靠商品号查询
public Goods findStudentById(String id){ System.out.print("goods");
//创建Data对象
Goods data=new Goods();
Statement stat=null;
ResultSet rs=null;
Connection conn=ConnectionDriver.getConnection(); String sql="select * from result where id='"+id+"'";
try {
stat=conn.createStatement();
//执行查询
rs=stat.executeQuery(sql);
//处理结果集
if(rs.next()){
//int id_id=rs.getInt(1);
String id_id=rs.getString(1); String name=rs.getString(2);
String address=rs.getString(3); double in_price=rs.getDouble(4);
double out_price=rs.getDouble(5); int jinhuo=rs.getInt(6);
int chuhuo=rs.getInt(7);
int kucun=rs.getInt(8); data.setId(id_id);
data.setName(name);
data.setAddress(address);
data.setIn_price(in_price);
data.setOut_price(out_price);
data.setKucun(kucun);
data.setJinhuo(jinhuo);
data.setChuhuo(chuhuo); }
} catch (SQLException e) {
e.printStackTrace();
}
return data;
} //对商品信息进行增加、修改、删除
public boolean updateStudent(String sql){
boolean flag=false;
Statement stat=null;
Connection conn=ConnectionDriver.getConnection();
try {
//生成Statement对象,向数据库发送sql指令
stat=conn.createStatement();
int i=stat.executeUpdate(sql);
if(i>0){
flag=true;
}
} catch (SQLException e) {
e.printStackTrace();
}finally{
JDBcloss.close(stat, conn);
} return flag;
}
}

最新文章

  1. window.open打开新窗口被浏览器拦截的处理方法
  2. 玩转GIT
  3. 通过a++来理解闭包改变作用域的问题
  4. dede channel 增加limit(属性)功能
  5. Textview在Listview中实现跑马灯效果
  6. Kafka+Storm+HDFS整合实践
  7. 协议Protocol
  8. HIbernate学习笔记(五) 关系映射之一对多与多对一
  9. bzoj1705
  10. ajax返回json数据示例
  11. border-radio属性
  12. PV IP UV
  13. APP-4-百度地图定位
  14. css 单行/多行文字垂直居中问题
  15. 背景图片自适应整个页面CSS+DIV
  16. 【RAC】使用一条“ps”命令获取Linux环境下全部RAC集群进程信息
  17. JQuery的几个基础操作
  18. Heka配置讲解
  19. 菜鸟天天不懂,那就天天敲它。。。还不懂。。。JAVA数组比较大小。
  20. leetcode笔记--1 two-sum

热门文章

  1. C# winform调用WebBrowser经典怪问题总结
  2. java之JAVA异常
  3. Oralce 导出脚本命令,定时执行
  4. MVC+Jqgrid
  5. web中国的数据分析过程
  6. 实例学习SSIS(四)--使用日志记录和错误流重定向
  7. SQL Server 2005中设置Reporting Services发布web报表的匿名访问
  8. leetcode[87] Partition List
  9. CodeSmith开发系列资料总结
  10. char* 转换成 CString