Read database contents in JSP (i)

Source: Internet
Author: User

In the JSP, read the contents of the database table as a table and add hyperlinks to the table:

1<%@ page language= "java" contenttype= "text/html; Charset=utf-8 "2pageencoding= "UTF-8"%>3<! DOCTYPE HTML PUBLIC "-//w3c//dtd HTML 4.01 transitional//en" "HTTP://WWW.W3.ORG/TR/HTML4/LOOSE.DTD" >4<%@ pageImport= "Java.io.*,java.util.*,java.sql.*"%>56<title> View Jobs </title>7<style type= "Text/css" >8 a:link {color:blue;}9 a:visited {color:blue;}Ten a:hover {color:red;} One</style> A -<table border= "1" width= "80%" align= "Center" > -<tr> the&LT;TD width= "Ten" valign= "Top" ><div align= "center" > Numbering </div></td> -&LT;TD width= "valign=" Top "><div align=" Center "> class </div></td> -&LT;TD width= "valign=" Top "><div align=" center "> Job Content </div></td> -&LT;TD width= "Ten" valign= "Top" ><div align= "center" > Activity Accessories </div></td> +</tr> -<% +Request.setcharacterencoding ("UTF-8"); AJava.sql.Connection conn = drivermanager.getconnection ("Jdbc:mysql://localhost:3306/login", "root", "123456"); atString sql1= "Select*from homework"; -Statement statemenet =(Statement) conn.createstatement (); -ResultSet rs1 =statemenet.executequery (SQL1); -  while(Rs1.next ()) { -%> -<tr> in&LT;TD width= "Ten" ><div align= "center" > <%=rs1.getstring ("number")%></div></td> -&LT;TD width= "Ten" ><div align= "center" > <%=rs1.getstring ("Class")%></div></td> to&LT;TD width= "Ten" ><div align= "center" > <%=rs1.getstring ("Job content")%></div></td> +&LT;TD width= "5" ><div align= "center" ><a href= "download_stu.jsp" style= "Text-decoration:none" > Downloads < /a></div></td> -</tr> the                    *<% $ } rs1.close (); Panax Notoginseng%> -</table>

The tables built with Navicat premium in the database are:

The result of the above program operation is:

Read database contents in JSP (i)

Related Article

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.