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

📄 bookinformation.jsp

📁 web书店应用程序
💻 JSP
字号:
<!-- Tutorial 32: bookInformation.jsp -->
<!-- Displays book information.       -->

<%-- import java.sql.* for database classes --%>
<%@ page import = "java.sql.*" %>

<!-- begin HTML document -->
<html>

   <!-- specify head element -->
   <head>
   
      <!-- specify page title -->
      <title>Book Information</title>
   </head>

   <!-- begin body of document -->
   <body>
   
      <!-- create a heading for the book's title -->
      <h1><%= request.getParameter( "bookTitle" ) %></h1>

      <%-- begin JSP scriptlet to connect to a database --%>
      <%
         // setup database connection
         try 
         {
            // specify database location
            System.setProperty( "db2j.system.home", 
               "C:\\Examples\\Tutorial29\\Databases" ); 

            // load Cloudscape driver
            Class.forName( "com.ibm.db2j.jdbc.DB2jDriver" );

            // obtain connection to database
            Connection connection = DriverManager.getConnection(
               "jdbc:db2j:bookstore" );

            // obtain list of titles from database
            if ( connection != null ) 
            {
               // create statement
               Statement statement = connection.createStatement();

               // execute query to get book information
               ResultSet results = statement.executeQuery( 
                  "SELECT cover, title, authors, price, isbn, " +
                  "edition, copyrightYear, description " +
                  "FROM products WHERE title = '" + 
                  request.getParameter( "bookTitle" ) + "'" );

               results.next();  // move cursor to the first row

      %>  <%-- end scriptlet to insert literal HTML --%>

               <!-- display book cover image -->
               <img src = "images/<%= results.getString( 
                  "cover" ) %>" alt = "Book cover for 
                  <%= results.getString( "title" ) %>.">
               
               <!-- display authors -->
               <p>Author(s): <%= results.getString( 
                  "authors" ) %></p>
               
               <!-- display price -->
               <p>Price: <%= results.getString( "price" ) %></p>

               <!-- display ISBN -->
               <p>ISBN: <%= results.getString( "isbn" ) %></p>

               <!-- display edition number -->
               <p>Edition: <%= results.getInt( "edition" ) %></p>
               
               <!-- display copyright year -->
               <p>Copyright Year: <%= results.getString( 
                  "copyrightYear" ) %></p>
                     
               <!-- display description -->
               <p>Description: <%= results.getString( 
                  "description" ) %></p>                 
            
               <!-- create link to Book List -->
               <p><a href = "books.jsp">Book List</a></p>
               
      <%  // continue scriptlet
            
               results.close();  // close result set
               connection.close();  // close database connection

			}  // end if

         }  // end try

         // catch SQLException
         catch( SQLException exception ) 
         {
            out.println( "Exception: " + exception + " occurred." );
         }

      %>  <%-- end scriptlet --%>

   </body>
</html>

 <!--
 **************************************************************************
 * (C) Copyright 1992-2004 by Deitel & Associates, Inc. and               *
 * Pearson Education, Inc. All Rights Reserved.                           *
 *                                                                        *
 * DISCLAIMER: The authors and publisher of this book have used their     *
 * best efforts in preparing the book. These efforts include the          *
 * development, research, and testing of the theories and programs        *
 * to determine their effectiveness. The authors and publisher make       *
 * no warranty of any kind, expressed or implied, with regard to these    *
 * programs or to the documentation contained in these books. The authors *
 * and publisher shall not be liable in any event for incidental or       *
 * consequential damages in connection with, or arising out of, the       *
 * furnishing, performance, or use of these programs.                     *
 **************************************************************************
-->
      

⌨️ 快捷键说明

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