📄 sellbackshoppingtreat.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.SellbackShopping;
import com.jxc.vo.Sellshopping;
import com.jxc.vo.Shopping;
import com.jxc.vo.Vo;
public class SellbackShoppingTreat 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 sellbackshopping 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) {
// TODO Auto-generated method stub
boolean flat = false;
SellbackShopping seb = (SellbackShopping) vo;
PreparedStatement pstm = null;
int rs = 0;
String sql = "insert into sellbackshopping(gid,oiprince,oinum,oitime,yid)values(?,?,?,?,?)";
try {
pstm = conn.prepareStatement(sql);
pstm.setString(1, seb.getGid());
pstm.setInt(2, seb.getOiprince());
pstm.setInt(3, seb.getOinum());
pstm.setDate(4, (Date) seb.getOitime());
pstm.setString(5, seb.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 boolean updateByid(Connection conn,int id, Vo vo) {
// TODO Auto-generated method stub
boolean flat = false;
SellbackShopping seb = (SellbackShopping) vo;
PreparedStatement pstm = null;
int rs = 0;
String sql = "update sellbackshopping set gid=?,oiprince=?,oinum=?,oitime=?,yid=? where id=?";
try {
pstm = conn.prepareStatement(sql);
pstm.setString(1, seb.getGid());
pstm.setInt(2, seb.getOiprince());
pstm.setInt(3, seb.getOinum());
pstm.setDate(4, (Date) seb.getOitime());
pstm.setString(5, seb.getYid());
pstm.setInt(6, 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 ArrayList<SellbackShopping> selectByTime(Connection conn,java.sql.Date d1,java.sql.Date d2) {
// TODO Auto-generated method stub
ArrayList<SellbackShopping> list = new ArrayList<SellbackShopping>();
PreparedStatement pstm = null;
ResultSet rs = null;
String sql = "select id,gid,oiprince,oinum,oitime,yid from sellbackshopping where oitime>=? and oitime<=?";
try {
pstm = conn.prepareStatement(sql);
pstm.setDate(1, d1);
pstm.setDate(2, d2);
rs = pstm.executeQuery();
while (rs.next()) {
SellbackShopping seb = new SellbackShopping();
seb.setId(rs.getInt(1));
seb.setGid(rs.getString(2));
seb.setOiprince(rs.getInt(3));
seb.setOinum(rs.getInt(4));
seb.setOitime(rs.getDate(5));
seb.setYid(rs.getString(6));
list.add(seb);
}
} 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
SellbackShopping vo=new SellbackShopping();
PreparedStatement pstm=null;
ResultSet rs=null;
String sql="select id,gid,oinum,oitime,yid from sellbackshopping where id=?";
try {
pstm=conn.prepareStatement(sql);
pstm.setInt(1, id);
rs=pstm.executeQuery();
if(rs.next()){
vo.setId(rs.getInt(1));
vo.setGid(rs.getString(2));
vo.setOinum(rs.getInt(3));
vo.setOitime(rs.getDate(4));
vo.setYid(rs.getString(5));
}
} 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 ArrayList<?> selectAll(Connection conn) {
// TODO Auto-generated method stub
return null;
}
public ArrayList<SellbackShopping> selectBySid(Connection conn,String sid,java.sql.Date d1,java.sql.Date d2){
ArrayList<SellbackShopping> list = new ArrayList<SellbackShopping>();
PreparedStatement pstm = null;
ResultSet rs = null;
String sql = "select id,gid,oiprince,oinum,oitime,yid from sellbackshopping where oitime>=? and oitime<=? and gid=?";
try {
pstm = conn.prepareStatement(sql);
pstm.setDate(1, d1);
pstm.setDate(2, d2);
pstm.setString(3, sid);
rs = pstm.executeQuery();
while (rs.next()) {
SellbackShopping seb = new SellbackShopping();
seb.setId(rs.getInt(1));
seb.setGid(rs.getString(2));
seb.setOiprince(rs.getInt(3));
seb.setOinum(rs.getInt(4));
seb.setOitime(rs.getDate(5));
seb.setYid(rs.getString(6));
list.add(seb);
}
} 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;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -