• 大小: 32.24MB
    文件类型: .zip
    金币: 2
    下载: 1 次
    发布日期: 2023-07-16
  • 语言: Java
  • 标签: 孙卫琴  Tomcat  Java  

资源简介

孙卫琴《Tomcat与Java Web开发技术详解》第二版光盘完整源代码,共33章,本人也在学习,代码可以直接运行,共33章的代码,完整版

资源截图

代码片段和文件信息

/** 直接通过JDBC API 访问MySQL数据库 */
package mypack;
import java.sql.*;
import javax.naming.*;
import javax.sql.*;
import java.util.*;

public class BookDB {

  private String dbUrl =  “jdbc:mysql://localhost:3306/BookDB“;
  private String dbUser=“dbuser“;
  private String dbPwd=“1234“;

  public BookDB () throws Exception{
     Class.forName(“com.mysql.jdbc.Driver“);
  }

  public Connection getConnection()throws Exception{
      return java.sql.DriverManager.getConnection(dbUrldbUserdbPwd);
  }

  public void closeConnection(Connection con){
    try{
        if(con!=null) con.close();
      }catch(Exception e){
        e.printStackTrace();
      }
  }

  public void closePrepStmt(PreparedStatement prepStmt){
    try{
        if(prepStmt!=null) prepStmt.close();
      }catch(Exception e){
        e.printStackTrace();
      }
  }

  public void closeResultSet(ResultSet rs){
    try{
        if(rs!=null) rs.close();
      }catch(Exception e){
        e.printStackTrace();
      }
  }

  public int getNumberOfBooks() throws Exception {
    Connection con=null;
    PreparedStatement prepStmt=null;
    ResultSet rs=null;
    int count=0;

    try {
      con=getConnection();
      String selectStatement = “select count(*) “ + “from BOOKS“;
      prepStmt = con.prepareStatement(selectStatement);
      rs = prepStmt.executeQuery();

      if (rs.next()) 
        count = rs.getInt(1);
 
    }finally{
      closeResultSet(rs);
      closePrepStmt(prepStmt);
      closeConnection(con);
    }
    return count;
  }


  public Collection getBooks()throws Exception{
    Connection con=null;
    PreparedStatement prepStmt=null;
    ResultSet rs =null;
    ArrayList books = new ArrayList();
    try {
      con=getConnection();
      String selectStatement = “select * “ + “from BOOKS“;
      prepStmt = con.prepareStatement(selectStatement);
      rs = prepStmt.executeQuery();

      while (rs.next()) {

        BookDetails bd = new BookDetails(rs.getString(1) rs.getString(2) rs.getString(3)
           rs.getFloat(4) rs.getInt(5) rs.getString(6)rs.getInt(7));
        books.add(bd);
      }

    }finally{
      closeResultSet(rs);
      closePrepStmt(prepStmt);
      closeConnection(con);
    }

    Collections.sort(books);
    return books;
  }

  public BookDetails getBookDetails(String bookId) throws Exception {
    Connection con=null;
    PreparedStatement prepStmt=null;
    ResultSet rs =null;
    try {
      con=getConnection();
      String selectStatement = “select * “ + “from BOOKS where ID = ? “;
      prepStmt = con.prepareStatement(selectStatement);
      prepStmt.setString(1 bookId);
      rs = prepStmt.executeQuery();

      if (rs.next()) {
        BookDetails bd = new BookDetails(rs.getString(1) rs.getString(2) rs.getString(3)
          rs.getFloat(4) rs.getInt(5) rs.getString(6)rs.getInt(7));
        prepStmt.close();

        

 属性            大小     日期    时间   名称
----------- ---------  ---------- -----  ----
     目录           0  2019-01-24 09:56  sourcecode\
     目录           0  2018-01-28 11:25  sourcecode\bookstores\
     文件         909  2008-07-12 12:42  sourcecode\bookstores\books.sql
     目录           0  2018-01-28 11:25  sourcecode\bookstores\version0\
     目录           0  2018-01-28 11:25  sourcecode\bookstores\version0\bookstore\
     文件          41  2008-07-12 12:42  sourcecode\bookstores\version0\bookstore\banner.jsp
     文件        1099  2008-07-12 12:42  sourcecode\bookstores\version0\bookstore\bookdetails.jsp
     文件         509  2008-07-12 12:42  sourcecode\bookstores\version0\bookstore\bookstore.jsp
     文件        1392  2008-07-12 12:42  sourcecode\bookstores\version0\bookstore\build.xml
     文件        1255  2008-07-12 12:42  sourcecode\bookstores\version0\bookstore\build0.xml
     文件         832  2008-07-12 12:42  sourcecode\bookstores\version0\bookstore\cashier.jsp
     文件        1540  2008-07-12 12:42  sourcecode\bookstores\version0\bookstore\catalog.jsp
     文件         349  2008-07-12 12:42  sourcecode\bookstores\version0\bookstore\common.jsp
     文件         353  2008-07-12 12:42  sourcecode\bookstores\version0\bookstore\errorpage.jsp
     文件       29382  2008-07-12 12:42  sourcecode\bookstores\version0\bookstore\logo.bmp
     文件         600  2008-07-12 12:42  sourcecode\bookstores\version0\bookstore\receipt.jsp
     文件        2402  2008-07-12 12:42  sourcecode\bookstores\version0\bookstore\showcart.jsp
     目录           0  2018-01-28 11:25  sourcecode\bookstores\version0\bookstore\src\
     目录           0  2018-01-28 11:25  sourcecode\bookstores\version0\bookstore\src\mypack\
     文件        5015  2008-07-12 12:42  sourcecode\bookstores\version0\bookstore\src\mypack\BookDB.java
     文件        1612  2008-07-12 12:42  sourcecode\bookstores\version0\bookstore\src\mypack\BookDetails.java
     文件        1981  2008-07-12 12:42  sourcecode\bookstores\version0\bookstore\src\mypack\ShoppingCart.java
     文件         762  2008-07-12 12:42  sourcecode\bookstores\version0\bookstore\src\mypack\ShoppingCartItem.java
     目录           0  2018-01-28 11:25  sourcecode\bookstores\version0\bookstore\WEB-INF\
     目录           0  2018-01-28 11:25  sourcecode\bookstores\version0\bookstore\WEB-INF\classes\
     目录           0  2018-01-28 11:25  sourcecode\bookstores\version0\bookstore\WEB-INF\classes\mypack\
     文件        5186  2008-07-12 12:42  sourcecode\bookstores\version0\bookstore\WEB-INF\classes\mypack\BookDB.class
     文件        1590  2008-07-12 12:42  sourcecode\bookstores\version0\bookstore\WEB-INF\classes\mypack\BookDetails.class
     文件        2420  2008-07-12 12:42  sourcecode\bookstores\version0\bookstore\WEB-INF\classes\mypack\ShoppingCart.class
     文件         788  2008-07-12 12:42  sourcecode\bookstores\version0\bookstore\WEB-INF\classes\mypack\ShoppingCartItem.class
     目录           0  2018-01-28 11:25  sourcecode\bookstores\version0\bookstore\WEB-INF\lib\
............此处省略1474个文件信息

评论

共有 条评论