📄 inbackshoppingtreat.java
字号:
package com.jxc.dao;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.sql.Date;
import com.jxc.vo.InbackShopping;
import com.jxc.vo.Vo;
public class InbackShoppingTreat implements Dao {
public boolean deleteById(Connection conn, int id) {
// TODO Auto-generated method stub
boolean flat=false;
PreparedStatement pstm=null;
int rs=0;
String sql="delete from inbackshopping where id=?";
try {
pstm=conn.prepareStatement(sql);
pstm.setInt(1, id);
rs=pstm.executeUpdate();
if(rs!=0)
flat=true;
else
flat=false;
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}finally{
try {
if(pstm!=null)
pstm.close();
if(conn!=null)
conn.close();
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
return flat;
}
public boolean insert(Connection conn, Vo vo) {
boolean flat=false;
InbackShopping shop=(InbackShopping)vo;
PreparedStatement pstm=null;
int rs=0;
String sql="insert into InbackShopping(sid,inprince,ionum,gid,iotime,yid)values(?,?,?,?,?,?)";
try {
pstm=conn.prepareStatement(sql);
//pstm.setInt(1, shop.getId());
pstm.setString(1, shop.getSid());
pstm.setInt(2, shop.getInprince());
pstm.setInt(3, shop.getIonum());
pstm.setString(4, shop.getGid());
pstm.setDate(5, (Date)shop.getIotime());
pstm.setString(6,shop.getYid());
rs=pstm.executeUpdate();
if(rs!=0)
flat=true;
else
flat=false;
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}finally{
try {
if(pstm!=null)
pstm.close();
if(conn!=null)
conn.close();
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
return flat;
}
public ArrayList<InbackShopping> selectAll(Connection conn) {
// TODO Auto-generated method stub
ArrayList<InbackShopping> list=new ArrayList<InbackShopping>();
PreparedStatement pstm=null;
ResultSet rs=null;
String sql="select id,sid,inprince,ionum,gid,iotime,yid from inbackshopping";
try {
pstm=conn.prepareStatement(sql);
rs=pstm.executeQuery();
while(rs.next()){
InbackShopping shop=new InbackShopping();
shop.setId(rs.getInt(1));
shop.setSid(rs.getString(2));
shop.setInprince(rs.getInt(3));
shop.setIonum(rs.getInt(4));
shop.setGid(rs.getString(5));
shop.setIotime(rs.getDate(6));
shop.setYid(rs.getString(7));
list.add(shop);
}
} 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 list;
}
public ArrayList<InbackShopping> selectByTime(Connection conn,Date d1,Date d2)
{
ArrayList<InbackShopping> list=new ArrayList<InbackShopping>();
PreparedStatement pstm=null;
ResultSet rs=null;
String sql="select id,sid,inprince,ionum,gid,iotime,yid from inbackshopping where iotime>=? and iotime<=?";
try {
pstm=conn.prepareStatement(sql);
pstm.setDate(1, d1);
pstm.setDate(2, d2);
rs=pstm.executeQuery();
while(rs.next()){
InbackShopping shop=new InbackShopping();
shop.setId(rs.getInt(1));
shop.setSid(rs.getString(2));
shop.setInprince(rs.getInt(3));
shop.setIonum(rs.getInt(4));
shop.setGid(rs.getString(5));
shop.setIotime(rs.getDate(6));
shop.setYid(rs.getString(7));
list.add(shop);
}
} 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 list;
}
public ArrayList<InbackShopping> selectBySid(Connection conn,String sid,Date d1,Date d2)
{
ArrayList<InbackShopping> list=new ArrayList<InbackShopping>();
PreparedStatement pstm=null;
ResultSet rs=null;
String sql="select id,sid,inprince,ionum,gid,iotime,yid from inbackshopping where iotime>=? and iotime<=? and sid=?";
try {
pstm=conn.prepareStatement(sql);
pstm.setDate(1, d1);
pstm.setDate(2, d2);
pstm.setString(3, sid);
rs=pstm.executeQuery();
while(rs.next()){
InbackShopping shop=new InbackShopping();
shop.setId(rs.getInt(1));
shop.setSid(rs.getString(2));
shop.setInprince(rs.getInt(3));
shop.setIonum(rs.getInt(4));
shop.setGid(rs.getString(5));
shop.setIotime(rs.getDate(6));
shop.setYid(rs.getString(7));
list.add(shop);
}
} 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 list;
}
public Vo selectById(Connection conn, int id) {
// TODO Auto-generated method stub
InbackShopping vo=new InbackShopping();
PreparedStatement pstm=null;
ResultSet rs=null;
String sql="select id,sid,inprince,ionum,iotime,gid,yid from inbackshopping 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.setInprince(rs.getInt(3));
vo.setIonum(rs.getInt(4));
vo.setIotime(rs.getDate(5));
vo.setGid(rs.getString(6));
vo.setYid(rs.getString(7));
}
} 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 flat=false;
InbackShopping shop=(InbackShopping)vo;
PreparedStatement pstm=null;
int rs=0;
String sql="update InbackShopping set sid=?,inprince=?,ionum=?,gid=?,iotime=?,yid=? where id=?";
try {
pstm=conn.prepareStatement(sql);
//pstm.setInt(1, shop.getId());
pstm.setString(1, shop.getSid());
pstm.setInt(2, shop.getInprince());
pstm.setInt(3, shop.getIonum());
pstm.setString(4, shop.getGid());
pstm.setDate(5, (Date)shop.getIotime());
pstm.setString(6,shop.getYid());
pstm.setInt(7, id);
rs=pstm.executeUpdate();
if(rs!=0)
flat=true;
else
flat=false;
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}finally{
try {
if(pstm!=null)
pstm.close();
if(conn!=null)
conn.close();
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
return flat;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -