⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 admindatabasebean.java

📁 java开发的网上书店
💻 JAVA
字号:
/* * AdminDataBaseBean.java * * Created on 2006年5月18日, 下午9:38 * * To change this template, choose Tools | Template Manager * and open the template in the editor. */package DAO;import Common.DbUtil;import VO.ProductBean;import java.sql.Connection;import java.sql.DriverManager;import java.sql.PreparedStatement;import java.sql.ResultSet;import java.sql.SQLException;import java.sql.Statement;import java.util.Vector;/** * * @author boyingking */public class AdminDataBaseBean {    private Connection con = null;    public Statement stmt = null;    private void connectTODB() {        try {            con = DbUtil.getConnection();        } catch (Exception e) {            e.printStackTrace();        }    }    /** Creates a new instance of AdminDataBaseBean */    public AdminDataBaseBean() {    }    public boolean adminLogin(String username,String password){        boolean loginok=false;        Statement stmt=null;        ResultSet rest=null;        this.connectTODB();        try {            stmt=con.createStatement();            rest=stmt.executeQuery("select * from admin where admin_id like '"+username+"' and password like '"+password+"'");            if(rest.next()){                loginok=true;            }else{                loginok=false;            }        } catch (SQLException ex) {            ex.printStackTrace();        } finally{            this.close(con,stmt,rest);        }        return loginok;    }    public Vector getAllProduct(){        Statement stmt=null;        ResultSet rest=null;        Vector vec=new Vector();        this.connectTODB();        try{            stmt=this.con.createStatement();            rest=stmt.executeQuery("select * from product");            while(rest.next()){                ProductBean temppro=new ProductBean();                temppro.setProductId(rest.getInt("product_id"));                temppro.setProductName(rest.getString("product_name"));                temppro.setProductPrice(rest.getDouble("product_price"));                temppro.setProductNum(rest.getInt("product_num"));                temppro.setProductDescribe(rest.getString("product_describe"));                vec.add(temppro);            }        }catch(Exception e){            e.printStackTrace();        }finally{            this.close(con,stmt,rest);        }          return vec;    }    public void deleteProduct(String id){        Statement stmt=null;        this.connectTODB();        int tempid=Integer.parseInt(id);        try{            stmt=this.con.createStatement();            stmt.execute("delete from product where product_id="+tempid);        }catch(Exception e){            e.printStackTrace();        }finally{            this.close(con,stmt,null);        }    }    public int addProduct(String id,String name,String price,String num,String describe){        PreparedStatement ps=null;        int line=-1;        int tempid=Integer.parseInt(id);        String tempname=name;        double tempprice=Double.parseDouble(price);        int tempnum=Integer.parseInt(num);        String tempdesc=describe;        this.connectTODB();        try {            ps=con.prepareStatement("insert into product values(?,?,?,?,?)" );            ps.setInt(1,tempid);            ps.setString(2,tempname);            ps.setDouble(3,tempprice);            ps.setInt(4,tempnum);            ps.setString(5,tempdesc);            line=ps.executeUpdate();        } catch (SQLException ex) {            ex.printStackTrace();        }finally{            try{                if(ps!=null){                    ps.close();                }if(con!=null){                    con.close();                }            }catch(Exception e){                e.printStackTrace();            }                   }        return line;    }    private void close(Connection con,Statement stmt,ResultSet rest){        try {            if(rest!=null){                rest.close();            }            if(stmt!=null){                stmt.close();            }            if(this.con!=null){                con.close();            }        }catch(Exception ee){            ee.printStackTrace();        }    }    public void closeDB(){        try{            if(stmt != null){                stmt.close();            }            con.close();        } catch(Exception SqlE){            SqlE.printStackTrace();        }    }}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -