亚洲国产日韩欧美一区二区三区,精品亚洲国产成人av在线,国产99视频精品免视看7,99国产精品久久久久久久成人热,欧美日韩亚洲国产综合乱

direktori cari
JSP 基礎(chǔ)教程 JSP 開發(fā)環(huán)境搭建 JSP 結(jié)構(gòu) JSP 生命周期 JSP 語法 JSP 指令 JSP 動(dòng)作元素 JSP 隱式對象 JSP 客戶端請求 JSP 服務(wù)器響應(yīng) JSP HTTP 狀態(tài)碼 JSP 表單處理 JSP 過濾器 JSP Cookies 處理 JSP Session JSP 文件上傳 JSP 日期處理 JSP 頁面重定向 JSP 點(diǎn)擊量統(tǒng)計(jì) JSP 自動(dòng)刷新 JSP 發(fā)送郵件 JSP 高級教程 JSP 標(biāo)準(zhǔn)標(biāo)簽庫(JSTL) <c:out> 標(biāo)簽 <c:set> 標(biāo)簽 <c:remove> 標(biāo)簽 <c:catch> 標(biāo)簽 <c:if> 標(biāo)簽 <c:choose> <c:import> 標(biāo)簽 <c:forEach> <c:param> 標(biāo)簽 <c:redirect> 標(biāo)簽 <fmt:formatNumber>標(biāo)簽 <fmt:parseNumber> 標(biāo)簽 <fmt:formatDate> 標(biāo)簽 <fmt:parseDate> 標(biāo)簽 <fmt:bundle> 標(biāo)簽 <fmt:setLocale> 標(biāo)簽 <fmt:setBundle> 標(biāo)簽 <fmt:timeZone> 標(biāo)簽 <fmt:setTimeZone> 標(biāo)簽 <fmt:message> 標(biāo)簽 <fmt:requestEncoding> 標(biāo)簽 <sql:setDataSource> 標(biāo)簽 <sql:query> 標(biāo)簽 <sql:update> 標(biāo)簽 <sql:param> 標(biāo)簽 <sql:dateParam> 標(biāo)簽 <sql:transaction> 標(biāo)簽 <x:out> 標(biāo)簽 <x:parse> 標(biāo)簽 <x:set> 標(biāo)簽 <x:if> 標(biāo)簽 <x:forEach> 標(biāo)簽 <x:choose> <x:transform> 標(biāo)簽 <x:param> 標(biāo)簽 fn:contains()函數(shù) fn:containsIgnoreCase()函數(shù) fn:endsWith()函數(shù) fn:escapeXml()函數(shù) fn:indexOf()函數(shù) fn:join()函數(shù) fn:length()函數(shù) fn:replace()函數(shù) fn:split()函數(shù) fn:startsWith()函數(shù) fn:substring()函數(shù) fn:substringAfter()函數(shù) fn:substringBefore()函數(shù) fn:toLowerCase()函數(shù) fn:toUpperCase()函數(shù) fn:trim()函數(shù) JSP 連接數(shù)據(jù)庫 JSP XML 數(shù)據(jù)處理 JSP JavaBean JSP 自定義標(biāo)簽 JSP 表達(dá)式語言 JSP 異常處理 JSP 調(diào)試 JSP 國際化
watak

JSP 連接數(shù)據(jù)庫


本章節(jié)假設(shè)您已經(jīng)對JDBC有一定的了解。在開始學(xué)習(xí)JSP數(shù)據(jù)庫訪問前,請確保JDBC環(huán)境已經(jīng)正確配置。

首先,讓我們按照下面的步驟來創(chuàng)建一個(gè)簡單的表并插入幾條簡單的記錄:


創(chuàng)建表

在數(shù)據(jù)庫中創(chuàng)建一個(gè)Employees表,步驟如下:

步驟1:

打開CMD,然后進(jìn)入數(shù)據(jù)庫安裝目錄:
C:\>
C:\>cd Program Files\MySQL\bin
C:\Program Files\MySQL\bin>

步驟2:

C:\Program Files\MySQL\bin>mysql -u root -p
Enter password: ********
mysql>

步驟3:

在TEST數(shù)據(jù)庫中創(chuàng)建Employee表:

mysql> use TEST;
mysql> create table Employees
    (
     id int not null,
     age int not null,
     first varchar (255),
     last varchar (255)
    );
Query OK, 0 rows affected (0.08 sec)
mysql>

插入數(shù)據(jù)記錄

創(chuàng)建好Employee表后,往表中插入幾條記錄:

mysql> INSERT INTO Employees VALUES (100, 18, 'Zara', 'Ali');
Query OK, 1 row affected (0.05 sec)
 
mysql> INSERT INTO Employees VALUES (101, 25, 'Mahnaz', 'Fatma');
Query OK, 1 row affected (0.00 sec)
 
mysql> INSERT INTO Employees VALUES (102, 30, 'Zaid', 'Khan');
Query OK, 1 row affected (0.00 sec)
 
mysql> INSERT INTO Employees VALUES (103, 28, 'Sumit', 'Mittal');
Query OK, 1 row affected (0.00 sec)
 
mysql>

SELECT操作

接下來的這個(gè)例子告訴我們?nèi)绾问褂肑STL SQL標(biāo)簽來運(yùn)行SQL SELECT語句:

<%@ page import="java.io.*,java.util.*,java.sql.*"%>
<%@ page import="javax.servlet.http.*,javax.servlet.*" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/sql" prefix="sql"%>
 
<html>
<head>
<title>SELECT Operation</title>
</head>
<body>
 
<sql:setDataSource var="snapshot" driver="com.mysql.jdbc.Driver"
     url="jdbc:mysql://localhost/TEST"
     user="root"  password="pass123"/>
 
<sql:query dataSource="${snapshot}" var="result">
SELECT * from Employees;
</sql:query>
 
<table border="1" width="100%">
<tr>
   <th>Emp ID</th>
   <th>First Name</th>
   <th>Last Name</th>
   <th>Age</th>
</tr>
<c:forEach var="row" items="${result.rows}">
<tr>
   <td><c:out value="${row.id}"/></td>
   <td><c:out value="${row.first}"/></td>
   <td><c:out value="${row.last}"/></td>
   <td><c:out value="${row.age}"/></td>
</tr>
</c:forEach>
</table>
 
</body>
</html>

訪問這個(gè)JSP例子,運(yùn)行結(jié)果如下:

mysql-access-1


INSERT操作

這個(gè)例子告訴我們?nèi)绾问褂肑STL SQL標(biāo)簽來運(yùn)行SQL INSERT語句:

<%@ page import="java.io.*,java.util.*,java.sql.*"%>
<%@ page import="javax.servlet.http.*,javax.servlet.*" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/sql" prefix="sql"%>
 
<html>
<head>
<title>JINSERT Operation</title>
</head>
<body>
 
<sql:setDataSource var="snapshot" driver="com.mysql.jdbc.Driver"
     url="jdbc:mysql://localhost/TEST"
     user="root"  password="pass123"/>


<sql:update dataSource="${snapshot}" var="result">
INSERT INTO Employees VALUES (104, 2, 'Nuha', 'Ali');
</sql:update>
 
<sql:query dataSource="${snapshot}" var="result">
SELECT * from Employees;
</sql:query>
 
<table border="1" width="100%">
<tr>
   <th>Emp ID</th>
   <th>First Name</th>
   <th>Last Name</th>
   <th>Age</th>
</tr>
<c:forEach var="row" items="${result.rows}">
<tr>
   <td><c:out value="${row.id}"/></td>
   <td><c:out value="${row.first}"/></td>
   <td><c:out value="${row.last}"/></td>
   <td><c:out value="${row.age}"/></td>
</tr>
</c:forEach>
</table>
 
</body>
</html>

訪問這個(gè)JSP例子,運(yùn)行結(jié)果如下:

mysql-access-2


DELETE操作

這個(gè)例子告訴我們?nèi)绾问褂肑STL SQL標(biāo)簽來運(yùn)行SQL DELETE語句:

<%@ page import="java.io.*,java.util.*,java.sql.*"%>
<%@ page import="javax.servlet.http.*,javax.servlet.*" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/sql" prefix="sql"%>
 
<html>
<head>
<title>DELETE Operation</title>
</head>
<body>
 
<sql:setDataSource var="snapshot" driver="com.mysql.jdbc.Driver"
     url="jdbc:mysql://localhost/TEST"
     user="root"  password="pass123"/>
 
<c:set var="empId" value="103"/>
 
<sql:update dataSource="${snapshot}" var="count">
  DELETE FROM Employees WHERE Id = ?
  <sql:param value="${empId}" />
</sql:update>
 
<sql:query dataSource="${snapshot}" var="result">
   SELECT * from Employees;
</sql:query>
 
<table border="1" width="100%">
<tr>
   <th>Emp ID</th>
   <th>First Name</th>
   <th>Last Name</th>
   <th>Age</th>
</tr>
<c:forEach var="row" items="${result.rows}">
<tr>
   <td><c:out value="${row.id}"/></td>
   <td><c:out value="${row.first}"/></td>
   <td><c:out value="${row.last}"/></td>
   <td><c:out value="${row.age}"/></td>
</tr>
</c:forEach>
</table>
 
</body>
</html>

訪問這個(gè)JSP例子,運(yùn)行結(jié)果如下:

mysql-access-3


UPDATE操作

這個(gè)例子告訴我們?nèi)绾问褂肑STL SQL標(biāo)簽來運(yùn)行SQL UPDATE語句:

<%@ page import="java.io.*,java.util.*,java.sql.*"%>
<%@ page import="javax.servlet.http.*,javax.servlet.*" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/sql" prefix="sql"%>
 
<html>
<head>
<title>DELETE Operation</title>
</head>
<body>
 
<sql:setDataSource var="snapshot" driver="com.mysql.jdbc.Driver"
     url="jdbc:mysql://localhost/TEST"
     user="root"  password="pass123"/>
 
<c:set var="empId" value="102"/>
 
<sql:update dataSource="${snapshot}" var="count">
  UPDATE Employees SET last = 'Ali' WHERE Id = ?
  <sql:param value="${empId}" />
</sql:update>
 
<sql:query dataSource="${snapshot}" var="result">
   SELECT * from Employees;
</sql:query>
 
<table border="1" width="100%">
<tr>
   <th>Emp ID</th>
   <th>First Name</th>
   <th>Last Name</th>
   <th>Age</th>
</tr>
<c:forEach var="row" items="${result.rows}">
<tr>
   <td><c:out value="${row.id}"/></td>
   <td><c:out value="${row.first}"/></td>
   <td><c:out value="${row.last}"/></td>
   <td><c:out value="${row.age}"/></td>
</tr>
</c:forEach>
</table>
 
</body>
</html>

訪問這個(gè)JSP例子,運(yùn)行結(jié)果如下:

mysql-access-4

關(guān)于我們 聯(lián)系我們 留言板

手冊網(wǎng)

Artikel sebelumnya: Artikel seterusnya: