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

📄 usercondb.java~50~

📁 用java实现的一个应用程序,源码非常完整,可以直接运行
💻 JAVA~50~
📖 第 1 页 / 共 2 页
字号:
package 毕业设计;
import java.sql.*;
import javax.swing.JOptionPane;
import java.util.Vector;
public class UserConDB {
    private Connection con;
    private Statement st;
    private ResultSet rs;
    private PreparedStatement pst;
    public UserConDB() {
        try {
            Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
        } catch (ClassNotFoundException ex) {
            System.out.println("Driver 出错");
        }
        try {
            String url = "jdbc:odbc:lib";
            con = DriverManager.getConnection(url);
            st = con.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE,
                                     ResultSet.CONCUR_UPDATABLE);
        } catch (SQLException ex1) {
            System.out.println("lib 出错");
        }
    }

    public boolean VerifyPassword(String Id, String Password) {
        boolean psw = false;
        try {
            String str = "select * from Operator where Id = '" + Id +
                         "' and Password = '" + Password + "'";
            rs = st.executeQuery(str);
            if (rs.next()) {
                psw = true;
            }
            rs.close();
        } catch (SQLException ex) {
        }
        return psw;
    }

    public void setIsUsing() {
        boolean psw = false;
        try {
            String str =
                    "Update Operator set IsUsing = '0' where IsUsing = '1'";
            pst = con.prepareStatement(str);
            pst.executeUpdate();
            pst.close();
        } catch (SQLException ex) {
        }
    }

    public void UpdateIsUsing(String Id) {
        boolean psw = false;
        try {
            String str = "Update Operator set IsUsing = '1' where Id = '" + Id +
                         "'";
            pst = con.prepareStatement(str);
            pst.executeUpdate();
            pst.close();
        } catch (SQLException ex) {
        }
    }

    public void UpdatePassword(String newPassword) {
        boolean psw = false;
        try {
            String str = "Update Operator set Password = '" + newPassword +
                         "' where IsUsing = '1'";
            pst = con.prepareStatement(str);
            pst.executeUpdate();
            pst.close();
        } catch (SQLException ex) {
        }
    }

    public Vector SearchAll() {
        Vector vt = new Vector();
        try {
            String str = "select * from Operator";
            rs = st.executeQuery(str);
            while (rs.next()) {
                Vector tempvt = new Vector();
                for (int i = 1; i <= rs.getMetaData().getColumnCount(); i++) {
                    if (i != 4)
                        tempvt.add(rs.getString(i));
                }
                vt.add(tempvt);
            }
            rs.close();
        } catch (SQLException ex) {
        }
        return vt;
    }

    public Vector SearchUser(String content, String sort, boolean isnot) {
        Vector vt = new Vector();
        if (isnot) {
            if (sort.equals("卡号")) {
                try {
                    String str = "select * from Operator where Id = '" +
                                 content +
                                 "'";
                    rs = st.executeQuery(str);
                    while (rs.next()) {
                        Vector tempvt = new Vector();
                        for (int i = 1; i <= rs.getMetaData().getColumnCount();
                                     i++) {
                            if (i != 4)
                                tempvt.add(rs.getString(i));
                        }
                        vt.add(tempvt);
                    }
                    rs.close();
                } catch (SQLException ex) {
                }
            } else if (sort.equals("姓名")) {
                try {
                    String str = "select * from Operator where Name = '" +
                                 content +
                                 "'";
                    rs = st.executeQuery(str);
                    while (rs.next()) {
                        Vector tempvt = new Vector();
                        for (int i = 1; i <= rs.getMetaData().getColumnCount();
                                     i++) {
                            if (i != 4)
                                tempvt.add(rs.getString(i));
                        }
                        vt.add(tempvt);
                    }
                    rs.close();
                } catch (SQLException ex) {
                }
            } else if (sort.equals("权限")) {
                try {
                    String str = "select * from Operator where Popedom = '" +
                                 content + "'";
                    rs = st.executeQuery(str);
                    while (rs.next()) {
                        Vector tempvt = new Vector();
                        for (int i = 1; i <= rs.getMetaData().getColumnCount();
                                     i++) {
                            if (i != 4)
                                tempvt.add(rs.getString(i));
                        }
                        vt.add(tempvt);
                    }
                    rs.close();
                } catch (SQLException ex) {
                }
            }
        } else {
            if (sort.equals("卡号")) {
                try {
                    String str = "select * from Operator where Id like '%" +
                                 content +
                                 "%'";
                    rs = st.executeQuery(str);
                    while (rs.next()) {
                        Vector tempvt = new Vector();
                        for (int i = 1; i <= rs.getMetaData().getColumnCount();
                                     i++) {
                            if (i != 4)
                                tempvt.add(rs.getString(i));
                        }
                        vt.add(tempvt);
                    }
                    rs.close();
                } catch (SQLException ex) {
                }
            } else if (sort.equals("姓名")) {
                try {
                    String str = "select * from Operator where Name like '%" +
                                 content +
                                 "%'";
                    rs = st.executeQuery(str);
                    while (rs.next()) {
                        Vector tempvt = new Vector();
                        for (int i = 1; i <= rs.getMetaData().getColumnCount();
                                     i++) {
                            if (i != 4)
                                tempvt.add(rs.getString(i));
                        }
                        vt.add(tempvt);
                    }
                    rs.close();
                } catch (SQLException ex) {
                }
            } else if (sort.equals("权限")) {
                try {
                    String str = "select * from Operator where Popedom like '%" +
                                 content + "%'";
                    rs = st.executeQuery(str);
                    while (rs.next()) {
                        Vector tempvt = new Vector();
                        for (int i = 1; i <= rs.getMetaData().getColumnCount();
                                     i++) {
                            if (i != 4)
                                tempvt.add(rs.getString(i));
                        }
                        vt.add(tempvt);
                    }
                    rs.close();
                } catch (SQLException ex) {
                }
            }
        }
        return vt;
    }

    public Vector SearchUser(String Id, String Name, String Popedom,
                             boolean isnot) {
        Vector vt = new Vector();
        if (isnot) {
            if (!Id.equals("") && Name.equals("") && Popedom.equals("")) {
                try {
                    String str = "select * from Operator where Id = '" + Id +
                                 "'";
                    rs = st.executeQuery(str);
                    while (rs.next()) {
                        Vector tempvt = new Vector();
                        for (int i = 1; i <= rs.getMetaData().getColumnCount();
                                     i++) {
                            if (i != 4)
                                tempvt.add(rs.getString(i));
                        }
                        vt.add(tempvt);
                    }
                    rs.close();
                } catch (SQLException ex) {
                }
            } else if (Id.equals("") && !Name.equals("") && Popedom.equals("")) {
                try {
                    String str = "select * from Operator where Name = '" + Name +
                                 "'";
                    rs = st.executeQuery(str);
                    while (rs.next()) {
                        Vector tempvt = new Vector();
                        for (int i = 1; i <= rs.getMetaData().getColumnCount();
                                     i++) {
                            if (i != 4)
                                tempvt.add(rs.getString(i));
                        }
                        vt.add(tempvt);
                    }
                    rs.close();
                } catch (SQLException ex) {
                }
            } else if (Id.equals("") && Name.equals("") && !Popedom.equals("")) {
                try {
                    String str = "select * from Operator where Popedom = '" +
                                 Popedom + "'";
                    rs = st.executeQuery(str);
                    while (rs.next()) {
                        Vector tempvt = new Vector();
                        for (int i = 1; i <= rs.getMetaData().getColumnCount();
                                     i++) {
                            if (i != 4)
                                tempvt.add(rs.getString(i));
                        }
                        vt.add(tempvt);
                    }
                    rs.close();
                } catch (SQLException ex) {
                }
            } else if (!Id.equals("") && !Name.equals("") && Popedom.equals("")) {
                try {
                    String str = "select * from Operator where Id = '" + Id +
                                 "' and Name = '" + Name + "'";
                    rs = st.executeQuery(str);
                    while (rs.next()) {
                        Vector tempvt = new Vector();
                        for (int i = 1; i <= rs.getMetaData().getColumnCount();
                                     i++) {
                            if (i != 4)

⌨️ 快捷键说明

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