📄 tejiabean.java
字号:
package Flower.model;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.util.Vector;
import java.util.Collection;
public class tejiaBean
{
Connection con=null;
PreparedStatement pstmt=null;
ResultSet rs=null;
PreparedStatement pstmt1=null;
ResultSet rs1=null;
public boolean addtejia(tejia tj) throws Exception
{
boolean res=false;
try
{
con=DBConnect.getConnection();
pstmt=con.prepareStatement("insert into tejia values(?,?)");
pstmt.setString(1,tj.getteid());
pstmt.setString(2,tj.getGoodsid());
pstmt.executeUpdate();
pstmt.close();
con.close();
res=true;
}
catch (Exception ex)
{
ex.printStackTrace();
}
return res;
}
public boolean updatetejia(tejia tj) throws Exception
{
boolean res=false;
try
{
con=DBConnect.getConnection();
pstmt=con.prepareStatement("update tejia set goodsid=? where teid=?");
pstmt.setString(1,tj.getGoodsid());
pstmt.setString(2,tj.getteid());
pstmt.executeUpdate();
pstmt.close();
con.close();
res=true;
}
catch (Exception ex)
{
ex.printStackTrace();
}
return res;
}
public boolean deltejia(String id)
{
boolean res=false;
try
{
con=DBConnect.getConnection();
pstmt=con.prepareStatement("delete from tejia where teid=?");
pstmt.setString(1,id);
pstmt.executeUpdate();
pstmt.close();
con.close();
res=true;
}
catch (Exception ex)
{
ex.printStackTrace();
}
return res;
}
public boolean getID(String id)
{
boolean res=false;
try
{
con=DBConnect.getConnection();
pstmt=con.prepareStatement("select * from tejia where teid=?");
pstmt.setString(1,id);
rs=pstmt.executeQuery();
if(rs.next())
{
res=true;
}
else
{
res=false;
}
rs.close();
pstmt.close();
con.close();
}
catch (Exception ex)
{
ex.printStackTrace();
}
return res;
}
public Collection findtejia(tejia tj) throws Exception
{
Vector v=new Vector();
try
{
con=DBConnect.getConnection();
if(tj.getteid().equals("")&&tj.getGoodsid().equals(""))
{
pstmt1=con.prepareStatement("select * from tejia");
rs1=pstmt1.executeQuery();
while(rs1.next())
{
tejia te=new tejia();
te.setteid(rs1.getString(1));
te.setGoodsid(rs1.getString(2));
v.add(te);
}
}
else
{
String s=" where ";
if(!tj.getteid().equals(""))
s=s+"teid like '%"+tj.getteid()+"%' and";
if(!tj.getGoodsid().equals(""))
s=s+" goodsid like '%"+tj.getGoodsid()+"%' and";
if(s.equals(" where "))
s="";
else
s=s.substring(0,s.lastIndexOf(" "));
pstmt=con.prepareStatement("select * from tejia"+s+"");
rs=pstmt.executeQuery();
while(rs.next())
{
tejia te=new tejia();
te.setteid(rs.getString(1));
te.setGoodsid(rs.getString(2));
v.add(te);
}
}
}
catch (Exception ex)
{
ex.printStackTrace();
}
return v;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -