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

📄 recordcondb.java

📁 用java实现的一个应用程序,源码非常完整,可以直接运行
💻 JAVA
字号:
package 毕业设计;
import java.sql.*;
import java.util.*;
public class RecordConDB {
    private Connection con;
    private Statement st;
    private ResultSet rs;
    private PreparedStatement pst;
    public RecordConDB() {
        //****************************连接数据库**********************************
         try {
             Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
         } catch (ClassNotFoundException ex) {
             System.out.println("Driver 出错");
         }
        try {
            String url = "jdbc:odbc:chenhaiLibrary";
            con = DriverManager.getConnection(url);
            st = con.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE,
                                     ResultSet.CONCUR_UPDATABLE);
        } catch (SQLException ex1) {
            System.out.println("lib 出错");
        }
        try {
        } catch (Exception ex) {
            ex.printStackTrace();
        }
        try {
            jbInit();
        } catch (Exception ex) {
            ex.printStackTrace();
        }
    }

    //*****************************添加借书记录*********************************
     public boolean AddRecord(String ReaId, String LibId, String BarCode,
                              String LoanTime, String RevertibleTime,
                              String Operator) {
         boolean Success = true;
         try {
             String strSQL = "insert Record values ( '" + ReaId + "', '" +
                             LibId + "', '" + BarCode + "', '" + LoanTime +
                             "', '', '" +
                             RevertibleTime + "', '" + Operator + "')";
             pst = con.prepareStatement(strSQL);
             pst.executeUpdate();
             pst.close();
         } catch (SQLException ex) {
             Success = false;
         }
         return Success;
     }

    //****************************查询记录**********************************
     public Vector SearchRecord(String LibId, String BarCode, String ReaId) {
         Vector vt = new Vector();
         String strSQL = "";
         if (BarCode.equals(""))
             strSQL = "select * from Record where ReaId = '" + ReaId +
                      "' and LibId = '" + LibId + "' and ReturnTime = ''";
         else
             strSQL = "select * from Record where ReaId = '" + ReaId +
                      "' and BarCode = '" + BarCode + "' and ReturnTime = ''";
         try {
             rs = st.executeQuery(strSQL);
             while (rs.next()) {
                 Record rd = new Record();
                 rd.setId(rs.getString(1));
                 rd.setReaId(rs.getString(2));
                 rd.setLibId(rs.getString(3));
                 rd.setBarCode(rs.getString(4));
                 rd.setLoanTime(rs.getString(5));
                 rd.setReturnTime(rs.getString(6));
                 rd.setRevertibleTime(rs.getString(7));
                 rd.setOperator(rs.getString(8));
                 vt.add(rd);
             }
             rs.close();
         } catch (SQLException ex) {
         }
         return vt;
     }

    //************************查询借书记录**************************************
     public Vector SearchLoanRecord() {
         Vector vt = new Vector();
         try {
             String strSQL = "select * from Record where ReturnTime = ''";
             rs = st.executeQuery(strSQL);
             while (rs.next()) {
                 Vector tempvt = new Vector();
                 for (int i = 1; i <= rs.getMetaData().getColumnCount(); i++) {
                     tempvt.add(rs.getString(i));
                 }
                 vt.add(tempvt);
             }
             rs.close();
         } catch (SQLException ex) {
         }
         return vt;
     }

    //**************************查询读者已借书记录******************************
     public Vector SearchAlreadyRecord(String ReaId) {
         Vector vt = new Vector();
         try {
             String strSQL = "select * from Record where ReaId = '" + ReaId +
                             "' and ReturnTime = ''";
             rs = st.executeQuery(strSQL);
             while (rs.next()) {
                 Vector tempvt = new Vector();
                 for (int i = 1; i <= rs.getMetaData().getColumnCount(); i++) {
                     tempvt.add(rs.getString(i));
                 }
                 vt.add(tempvt);
             }
             rs.close();
         } catch (SQLException ex) {
         }
         return vt;
     }

    //*************************还书时更新记录*************************************
     public void ReturnBookRecord(int Id, String ReturnTime) {
         try {
             String strSQL = "update Record set ReturnTime = '" + ReturnTime +
                             "' where Id = " + Id;
             pst = con.prepareStatement(strSQL);
             pst.executeUpdate();
             pst.close();
         } catch (SQLException ex) {
         }
     }

    //*****************************关闭数据库*********************************
     public void CloseRecordDB() {
         try {
             st.close();
             con.close();
         } catch (SQLException ex) {
         }
     }

    private void jbInit() throws Exception {
    }
}

⌨️ 快捷键说明

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