• JSP与Access2010结合,实现数据的交互使用


    主要的jsp文件:

    student.jsp
     1 <%@ page import="java.io.*" %>
     2 <%@ page import="java.sql.*" %>
     3 <%@ page import="java.util.*" %>
     4 <%@ page language="java" contentType="text/html; charset=utf-8"
     5     pageEncoding="utf-8"%>
     6 <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
     7 <html>
     8 <head>
     9 <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
    10 <title>Student_Infomation</title>
    11 </head>
    12 <body>
    13 <center>
    14     <h1>STUDENTS_INFOMATIONS</h1>
    15     <hr>
    16 <%
    17 try{
    18     Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
    19     Connection con;
    20     Statement stmt;
    21     ResultSet rs;
    22     String url="jdbc:odbc:DRIVER={Microsoft Access Driver (*.mdb, *.accdb)};DBQ=D:/student.accdb";
    23 
    24     con=DriverManager.getConnection(url);
    25     stmt=con.createStatement();
    26     rs = stmt.executeQuery("SELECT * FROM student");
    27 %>
    28         <table border=1>
    29             <tr>
    30                 <td>StudentNum</td>
    31                 <td>StudentName</td>
    32                 <td>StudentAge</td>
    33                 <td>StudentAddr</td>
    34                 <td>StudentSch</td>
    35                 <td>StudentMaj</td>
    36                 <td>StudentScore</td>
    37             </tr>
    38 <%
    39         while(rs.next()){
    40             out.println("<tr>");
    41             out.println("<td>"+rs.getInt("num")+"</td>");
    42             out.println("<td>"+rs.getString("name")+"</td>");
    43             out.println("<td>"+rs.getInt("age")+"</td>");
    44             out.println("<td>"+rs.getString("fromw")+"</td>");
    45             out.println("<td>"+rs.getString("school")+"</td>");
    46             out.println("<td>"+rs.getString("major")+"</td>");
    47             out.println("<td>"+rs.getInt("score")+"</td>");
    48             out.println("</tr>");
    49         }
    50 
    51     rs.close();
    52     stmt.close();
    53     con.close();
    54 }catch(Exception e){out.println(e.getMessage());}
    55 %>
    56         </table>
    57 </center>
    58 </body>
    59 </html>

    修改web.xml

    WEB.xml
     1 <?xml version="1.0" encoding="utf-8"?>
     2 
     3 <web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
     4     xmlns="http://java.sun.com/xml/ns/javaee"
     5     xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
     6     xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" id="WebApp_ID" version="2.5">
     7 
     8   <display-name>Student</display-name>
     9   <description>
    10      Query the information of students from Access Database
    11   </description>
    12 </web-app>
  • 相关阅读:
    HashMap是无序的
    mysql随笔
    visual stdio 安装OpenGL库文件
    myeclipse解决JSP文件里script背景颜色的调整
    js的鼠标事件整理-------Day47
    Linux环境编程之IPC进程间通信(五):Posix消息队列1
    HDFS 读取、写入、遍历文件夹获取文件全路径、append
    Appfuse搭建过程(下源代码不须要maven,lib直接就在项目里(否则痛苦死!))
    CSS样式命名规则
    关于c++ list容器的操作摸索
  • 原文地址:https://www.cnblogs.com/wocn/p/db_jsp_datasource_Select.html
Copyright © 2020-2023  润新知