📄 inshoppingtreat.java
字号:
package com.jxc.dao;
import java.sql.Connection;
import java.sql.Date;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import com.jxc.vo.InShopping;
import com.jxc.vo.Shopping;
import com.jxc.vo.Vo;
public class InShoppingTreat implements Dao
{
public boolean deleteById(Connection conn,int id)//删除错误的进货纪录
{
boolean isRun=false;
int num=0;
PreparedStatement pstat=null;
String sql="delete from inshopping where id=? ";
try{
pstat=conn.prepareStatement(sql);
pstat.setInt(1, id);//将id的值赋给sid
num=pstat.executeUpdate();
if(num!=0)
isRun=true;
else
isRun=false;
}catch(SQLException e){
e.printStackTrace();
}finally{
try
{
if(pstat!=null)
pstat.close();
if(conn!=null)
conn.close();
} catch (SQLException e)
{
e.printStackTrace();
}
}
return isRun;
}
public ArrayList<InShopping> selectByTime(Connection conn,Date d1,Date d2)//按时间段查询进货纪录
{
ArrayList<InShopping> list=new ArrayList<InShopping>();
PreparedStatement pstat=null;
ResultSet rs=null;
String sql="select sid,intprince,innum,intime,yid from inshopping where intime>=? and intime<=?";
try{
InShopping in=new InShopping();
pstat=conn.prepareStatement(sql);
pstat.setDate(1,d1);
pstat.setDate(2,d2);
rs=pstat.executeQuery();
while(rs.next()){
in.setSid(rs.getString(1));
in.setIntprince(rs.getInt(2));
in.setInnum(rs.getInt(3));
in.setIntime(rs.getDate(4));
in.setYid(rs.getString(5));
list.add(in);
}
}catch(SQLException e){
e.printStackTrace();
}finally{
try
{
if(rs!=null)
rs.close();
if(pstat!=null)
pstat.close();
if(conn!=null)
conn.close();
} catch (SQLException e)
{
e.printStackTrace();
}
}
return list;
}
public Vo selectById(Connection conn, int id) {
// TODO Auto-generated method stub
InShopping vo=new InShopping();
PreparedStatement pstm=null;
ResultSet rs=null;
String sql="select id, sid,intprince,innum,intime,yid from inshopping where id=?";
try {
pstm=conn.prepareStatement(sql);
pstm.setInt(1, id);
rs=pstm.executeQuery();
if(rs.next()){
vo.setId(rs.getInt(1));
vo.setSid(rs.getString(2));
vo.setIntprince(rs.getInt(3));
vo.setInnum(rs.getInt(4));
vo.setIntime(rs.getDate(5));
vo.setYid(rs.getString (6));
}
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}finally{
try {
if(rs!=null)
rs.close();
if(pstm!=null)
pstm.close();
if(conn!=null)
conn.close();
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
return vo;
}
public boolean updateById(Connection conn, int id, Vo vo)
{
boolean isRun=false;
int num=0;
PreparedStatement pstat=null;//sid,intprince,innum,intime,yid
String sql="update inshopping set sid=?,intprince=?,innum=?,intime=?,yid=? where id=?";
try{
InShopping in=(InShopping)vo;
pstat=conn.prepareStatement(sql);
pstat.setInt(6, id);
pstat.setString(1, in.getSid());
pstat.setInt(2,in.getIntprince());
pstat.setInt(3,in.getInnum());
pstat.setDate(4,in.getIntime());
pstat.setString(5, in.getYid());
num=pstat.executeUpdate();
if(num!=0)
isRun=true;
else
isRun=false;
}catch(SQLException e){
e.printStackTrace();
}
return isRun;
}
public boolean insert(Connection conn, Vo vo) {
// TODO Auto-generated method stub
boolean isRun = false;
PreparedStatement pstat = null;
int num = 0;
String sql = "insert into inshopping (sid,intprince,innum,intime,yid )values(?,?,?,?,?)";
try
{
InShopping inshop = (InShopping) vo;
pstat = conn.prepareStatement(sql);
pstat.setString(1, inshop.getSid());
pstat.setInt(2, inshop.getIntprince());
pstat.setInt(3, inshop.getInnum());
pstat.setDate(4, inshop.getIntime());
pstat.setString(5, inshop.getYid());
num = pstat.executeUpdate();
if (num != 0)
isRun = true;
else
isRun = false;
} catch (SQLException e)
{
e.printStackTrace();
}finally{
try
{
if(pstat!=null)
pstat.close();
if(conn!=null)
conn.close();
} catch (SQLException e)
{
e.printStackTrace();
}
}
return isRun;
}
public ArrayList<?> selectAll(Connection conn) {
// TODO Auto-generated method stub
PreparedStatement pstat=null;
ArrayList<InShopping> list=new ArrayList<InShopping>();
ResultSet rs=null;
String sql="select id, sid,intprince,innum,intime,yid from inshopping";
try
{
pstat=conn.prepareStatement(sql);
rs=pstat.executeQuery();
while(rs.next())
{
InShopping in=new InShopping();
in.setId(rs.getInt(1));
in.setSid(rs.getString(2));
in.setIntprince(rs.getInt(3));
in.setInnum(rs.getInt(4));
in.setIntime(rs.getDate(5));
in.setYid(rs.getString(6));
list.add(in);
}
}catch(SQLException e){
e.printStackTrace();
}finally{
try
{
if(rs!=null)
rs.close();
if(pstat!=null)
pstat.close();
if(conn!=null)
conn.close();
} catch (SQLException e)
{
e.printStackTrace();
}
}
return list;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -