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

📄 cons.java~17~

📁 图书管理 问题描述:图书管理基本业务活动包括对一本书的采编入库、清除库存、借阅和归还等等。将上述业务活动借助于计算机系统完成。
💻 JAVA~17~
字号:
package jxm;

import java.sql.*;
import java.util.Vector;

/**
 * <p>Title: </p>
 *
 * <p>Description: </p>
 *
 * <p>Copyright: Copyright (c) 2007</p>
 *
 * <p>Company: </p>
 *
 * @author not attributable
 * @version 1.0
 */
public class cons {
    public cons() {
        try {
            jbInit();
        } catch (Exception ex) {
            ex.printStackTrace();
        }
    }

    public static Connection getcon() {
        try {
            Class.forName("com.microsoft.jdbc.sqlserver.SQLServerDriver");
            Connection con = DriverManager.getConnection(
                    "jdbc:microsoft:sqlserver://127.0.0.1;DatabaseName=bookk",
                    "sa", "ok");
            return con;
        } catch (Exception ex) {

        }
        return null;

    }

    public boolean getbl(String str) {  //查询数据库中是否有数据 return boolean
        Connection con = null;            // 此函数通用
        Statement st = null;
        ResultSet rs = null;
        try {
            con = cons.getcon();
            st = con.createStatement();
            rs = st.executeQuery(str);
            if (rs.next()) {
                return true;
            }
        } catch (Exception ex) {
            System.out.println(ex);
        }
        return false;
    }

    public ResultSet getrs(String str) {   //查询数据库中数据    此函数通用 return resultset
        Connection con = null;
        Statement st = null;
        ResultSet rs = null;
        try {
            con = cons.getcon();
            st = con.createStatement();
            rs = st.executeQuery(str);
            return rs;
        } catch (Exception ex) {
            System.out.println(ex);
        }
        return null;
    }
public boolean getblcc(String str){    //增 删 改 函数 return bl  通用
    Connection con = null;
           Statement st = null;
           int i=0;
       try {
           con=cons.getcon();
           st=con.createStatement();
           i=st.executeUpdate(str);
           if(i>0)
               return true;
       } catch (Exception ex) {
           System.out.println(ex);
       }
       return false;

}
    public Vector getbookve(String str) { // 查询图书资料 把图书资料表封装成集合[books]表
        Vector ve = new Vector();/////////////////////
        jbbooks j;
        Connection con = null;
        Statement st = null;
        ResultSet rs = null;

        try {
            con = cons.getcon();
            st = con.createStatement();
            rs = st.executeQuery(str);
            while (rs.next()) {
                j=new jbbooks();
                j.setBnum(rs.getString(1));
                j.setBname(rs.getString(2));
                j.setBze(rs.getString(3));
                j.setBcbs(rs.getString(4));
                j.setBtype(rs.getString(5));

                j.setBprice(rs.getString(6));
                j.setBpage(rs.getString(7));
                j.setBaddress(rs.getString(8));
                j.setBzt(rs.getString(9));
                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 getuserve(String str) { //查询读者资料 并封装成集合  [duze] 表
        Vector ve = new Vector();
        jbuser j;
        Connection con = null;
        Statement st = null;
        ResultSet rs = null;
        try {
            con = cons.getcon();
            st = con.createStatement();
            rs = st.executeQuery(str);
            while (rs.next()) {
                j=new jbuser();
                j.setDnum(rs.getString(1));
                j.setDname(rs.getString(2));
                j.setDsex(rs.getString(3));
                j.setDdh(rs.getString(4));
                j.setDaddress(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;

    } //end getserve
    public Vector getjbkve(String str) { //查询借出借入资料 并封装成集合  [jhbook] 表
     Vector ve = new Vector();
     jbjhbook j=new jbjhbook();
     Connection con = null;
     Statement st = null;
     ResultSet rs = null;
     try {
         con = cons.getcon();
         st = con.createStatement();
         rs = st.executeQuery(str);
         while (rs.next()) {
            j.setBookid(rs.getString(1));
            j.setUserid(rs.getString(2));
            j.setStarttime(rs.getDate(3));  //Date
            j.setEndtime(rs.getDate(4));    //Date
            j.setBorrowtime(rs.getString(5));
            j.setYamoney(rs.getString(6));
            j.setZumoney(rs.getString(7));

             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;

 } //end getserve

    private void jbInit() throws Exception {
    }
}

⌨️ 快捷键说明

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