Access the Access database (JSP + Tomcat5.5.20)

Source: Internet
Author: User
The following example shows how to access a student information table: first, create the access database file student. mdb: Open the Table Designer, enter the field name and data type respectively, and set the primary key. Second, set the test data: studentnumnameagefromwschoolmajorscore200706001 Zhang Fei 19 Jilin University of Jilin 388 linguistics

The following example shows how to access a student information table: first, create the access database file student. mdb, open the Table Designer, enter the field name and data type, and set the primary key. Second, create the test data: student num name age fromw school major score 200706001 Zhang Fei 19 Jilin University linguistics 388

ToAccessAn example of a student information table is as follows:

First, create accessDatabaseIn the student. mdb file, open the Table Designer, enter the field name and data type respectively, and set the primary key:

Second, establish test data:

Student
Num Name Age Fromw School Major Score
200706001 Zhang Fei 19 Jilin Province Jilin University Linguistics 388
200706002 Liu Bei 20 Jilin Province Northeast Normal University Japanese 328
200706003 Guan Yu 19 Beijing Peking University Computer Software and Theory 421
200706004 Mink Zen 18 Sichuan Sichuan University Electronic Information Engineering 376
200706005 Guan Hanqing 18 Zhejiang Zhejiang University Computational Mathematics 375
200706006 Qu Yi 20 Zhejiang Zhejiang University Application chemistry 402
200706007 Oman 19 Beijing Peking University Library Management 314
200706008 Abei 19 Beijing Beijing University of Aeronautics and Astronautics Thermal Energy and Power Engineering 348
200706009 Wu Zetian 19 Shanghai Fudan University European and American Literature 399
200706010 Liu Yunlong 18 Liaoning Shenyang Industrial University Mechanical Manufacturing 416
200706011 Fangge 19 Liaoning Dalian University of Technology Applied Mathematics 333
200706012 Wang da 21 Tianjin Tianjin University Network applications 342
200706013 Xi Shi 18 Tianjin Nankai University Data Warehouse 411
200706014 Li Shimin 18 Jilin Province Changchun University of Technology Information Management and Information System 364
200706015 Wang Mang 19 Hubei Province Wuhan University Solar energy 294
200706016 Zhu Yuanzhang 18 Hubei Province Wuhan University Geothermal energy 352
200706017 Zhuge Liang 19 Beijing Tsinghua University Data Mining Technology 434
200706018 Shida 20 Beijing Beijing University of Science and Technology Energy Machine Engineering 319
200706019 Hongfeng candle 18 Beijing Beijing International Studies University Foreign Language Culture 347
200706020 Liu Yan 18 Heilongjiang Harbin Institute of Technology Electrical Engineering and automation 405

Place student. db in the D: \ root directory.

Create and configure the Data source: the data source name is student.

Then, create a Student file directory under the path Apache Software Foundation \ Tomcat 5.5 \ webapps and write jsp file code under the directory:

<% ... @ Page contentType="Text/html; charset = gb2312"Language="Java"Import="Java. SQL. *, java. io .*" %>
< Html >
< Body >
< Center >
< H1 > Student admission Information <SPAN>H1>
<Hr>
<TableBorder= 1>
<Tr> <Td>Student ID<SPAN>Td> <Td>Name<SPAN>Td> <Td>Age<SPAN>Td> <Td>From<SPAN>Td> <Td>Schools<SPAN>Td> <Td>Professional<SPAN>Td> <Td>Score<SPAN>Td> <SPAN>Tr>
<%...
Class. forName ("Sun. jdbc. odbc. JdbcOdbcDriver");
StringUrl="Jdbc: odbc: driver = {Microsoft Access Driver (*. mdb)}; DBQ = D:/student. mdb";
Connection con=DriverManager. getConnection (url );
Statement stmt=Con. createStatement ();
ResultSet rst=Stmt.exe cuteQuery ("Select * from student");
While(Rst. next ())
{
Out. PRintln ("");
Out. println (""+Rst. getInt ("Num")+"

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.