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

📄 db.java

📁 班级管理系统
💻 JAVA
字号:
package myproject;
import java.sql.DriverManager;
import java.sql.Statement;
import java.sql.Connection;
import java.sql.SQLException;
import java.sql.ResultSet;
import java.util.Vector;
import java.sql.*;
public class DB {
    private Connection con;
    private Statement st;
    private ResultSet rs;
    public DB() {
        try {
            Class.forName("com.microsoft.jdbc.sqlserver.SQLServerDriver");
            con=DriverManager.getConnection("jdbc:microsoft:sqlserver://localhost;DatabaseName=mianmu;","sa","");
            st=con.createStatement();
        } catch (ClassNotFoundException ex) {
        } catch (SQLException ex) {
            /** @todo Handle this exception */
        }
    }
    public boolean getblcc(String str) { //增 删 改
        System.out.println(str);
        int i = 0;
        try {
            st = con.createStatement();

            i = st.executeUpdate(str);
            //  System.out.println(i);
            if (i > 0) {
                return true;
            }
        } catch (Exception ex) {
            System.out.println(ex);
        } finally {
            try {
                if (st != null) {
                    st.close();
                }
                if (con != null) {
                    con.close();
                }
            } catch (Exception ex) {
                System.out.println(ex);
            }
        }

        return false;

    }
    public ResultSet Select(String str)
   {
       try {
           rs = st.executeQuery(str);
       } catch (SQLException ex) {
       }
       return rs;
   }
   public int Update(String str)
   {
       int x=0;
       try {
           x = st.executeUpdate(str);
       } catch (SQLException ex) {
       }
       return x;
   }
   public Vector getuserve(String str) { //查询资料 并封装成集合
        Vector ve = new Vector();
        jbuser j;
        try {
            Class.forName("com.microsoft.jdbc.sqlserver.SQLServerDriver");
            con=DriverManager.getConnection("jdbc:microsoft:sqlserver://localhost;DatabaseName=mianmu;","sa","");
            st = con.createStatement();
            rs = st.executeQuery(str);
            while (rs.next()) {
                j = new jbuser();
                j.setDnum(rs.getString(1));
                j.setDyy(rs.getString(2));
                j.setDyw(rs.getString(3));
                j.setDsj(rs.getString(4));
                j.setDgd(rs.getString(5));
                ve.add(j);
            }
            return ve;
        } catch (Exception ex) {
            System.out.println(ex);
        } finally {
            try {
                if (rs != null) {
                    rs.close();
                }
                if (st != null) {
                    st.close();
                }
                if (con != null) {
                    con.close();
                }
            } catch (Exception ex) {
                System.out.println(ex);
            }
        }

        return null;

    }
    public Vector getuserve1(String str) { //查询资料 并封装成集合
            Vector ve = new Vector();
            jbuser1 j;
            try {
                Class.forName("com.microsoft.jdbc.sqlserver.SQLServerDriver");
                con=DriverManager.getConnection("jdbc:microsoft:sqlserver://localhost;DatabaseName=mianmu;","sa","");
                st = con.createStatement();
                rs = st.executeQuery(str);
                while (rs.next()) {
                    j = new jbuser1();
                    j.setDname(rs.getString(1));
                    j.setDxh(rs.getString(2));
                    j.setDQQ(rs.getString(3));
                    j.setDxb(rs.getString(4));
                    ve.add(j);
                }
                return ve;
            } catch (Exception ex) {
                System.out.println(ex);
            } finally {
                try {
                    if (rs != null) {
                        rs.close();
                    }
                    if (st != null) {
                        st.close();
                    }
                    if (con != null) {
                        con.close();
                    }
                } catch (Exception ex) {
                    System.out.println(ex);
                }
            }

            return null;

    }
   public void Close()
   {
       if(rs!=null)
           try {
               rs.close();
           } catch (SQLException ex) {
           }
       if(st!=null)
           try {
               st.close();
           } catch (SQLException ex1) {
           }
       if(con!=null)
           try {
               con.close();
           } catch (SQLException ex2) {
           }
   }
}

⌨️ 快捷键说明

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