📄 shoppingtreat.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 com.jxc.vo.Shopping;
import com.jxc.vo.Vo;
public class ShoppingTreat implements Dao {
public boolean deleteById(Connection conn, String id) {
// TODO Auto-generated method stub
boolean flat=false;
PreparedStatement pstm=null;
int rs=0;
String sql="delete from shopping where sid=?";
try {
pstm=conn.prepareStatement(sql);
pstm.setString(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;
Shopping shop=(Shopping)vo;
PreparedStatement pstm=null;
int rs=0;
String sql="insert into shopping(sid,sname,stype,gid,sinfo,ssccs)values(?,?,?,?,?,?)";
try {
pstm=conn.prepareStatement(sql);
pstm.setString(1, shop.getSid());
pstm.setString(2, shop.getSname());
pstm.setString(3, shop.getStype());
pstm.setString(4, shop.getGid());
pstm.setString(5, shop.getSinfo());
pstm.setString(6,shop.getSsccs());
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<Shopping> selectAll(Connection conn) {
// TODO Auto-generated method stub
ArrayList<Shopping> list=new ArrayList<Shopping>();
PreparedStatement pstm=null;
ResultSet rs=null;
String sql="select sid,sname,stype,gid,sinfo,ssccs from shopping";
try {
pstm=conn.prepareStatement(sql);
rs=pstm.executeQuery();
while(rs.next()){
Shopping shop=new Shopping();
shop.setSid(rs.getString(1));
shop.setSname(rs.getString(2));
shop.setStype(rs.getString(3));
shop.setGid(rs.getString(4));
shop.setSinfo(rs.getString(5));
shop.setSsccs(rs.getString(6));
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<Shopping> selectByType(Connection conn,String stype) {
// TODO Auto-generated method stub
ArrayList<Shopping> list=new ArrayList<Shopping>();
PreparedStatement pstm=null;
ResultSet rs=null;
String sql="select sid,sname,stype,gid,sinfo,ssccs from shopping where stype=?";
try {
pstm=conn.prepareStatement(sql);
pstm.setString(1, stype);
rs=pstm.executeQuery();
while(rs.next()){
Shopping shop=new Shopping();
shop.setSid(rs.getString(1));
shop.setSname(rs.getString(2));
shop.setStype(rs.getString(3));
shop.setGid(rs.getString(4));
shop.setSinfo(rs.getString(5));
shop.setSsccs(rs.getString(6));
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, String id) {
// TODO Auto-generated method stub
Shopping vo=new Shopping();
PreparedStatement pstm=null;
ResultSet rs=null;
String sql="select sid,sname,stype,gid,sinfo,ssccs from shopping where sid=?";
try {
pstm=conn.prepareStatement(sql);
pstm.setString(1, id);
rs=pstm.executeQuery();
if(rs.next()){
vo.setSid(rs.getString(1));
vo.setSname(rs.getString(2));
vo.setStype(rs.getString(3));
vo.setGid(rs.getString(4));
vo.setSinfo(rs.getString (5));
vo.setSsccs(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 selectId(Connection conn, String id) {
// TODO Auto-generated method stub
boolean flat=false;
PreparedStatement pstm=null;
ResultSet rs=null;
String sql="select * from shopping where sid=?";
try {
pstm=conn.prepareStatement(sql);
pstm.setString(1, id);
rs=pstm.executeQuery();
if(rs.next()){
flat=true;
}else{
flat=false;
}
} 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 flat;
}
public boolean updateById(Connection conn, String id, Vo vo) {
// TODO Auto-generated method stub
boolean falt=false;
Shopping shop=(Shopping)vo;
PreparedStatement pstm=null;
int rs=0;
String sql="update shopping set sid=?,sname=?,stype=?,gid=?,sinfo=?,ssccs=? where sid=?";
try {
pstm=conn.prepareStatement(sql);
pstm.setString(1,shop.getSid());
pstm.setString (2,shop.getSname());
pstm.setString(3, shop.getStype());
pstm.setString(4, shop.getGid());
pstm.setString(5, shop.getSinfo());
pstm.setString(6, shop.getSsccs());
pstm.setString(7, id);
rs=pstm.executeUpdate();
if(rs!=0)
falt=true;
else
falt=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 falt;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -