【实训目的】
(1)掌握利用JDBC实现数据库的添加操作
(2)掌握利用JDBC实现数据库的更新操作
(3)利用JDBC实现数据库的查询操作
(4)利用JDBC实现数据库的删除操作
【实训要求】
(1)创建insert.jsp页面
(2)创建update.jsp
(3)创建query.jsp
(4)创建delete.jsp
1、insert.jsp
<%@ page import="java.sql.Connection" %>
<%@ page import="java.sql.Statement" %>
<%@ page import="java.sql.DriverManager" %>
<%@ page import="java.sql.SQLException" %><%--
Created by IntelliJ IDEA.
User: 12526
Date: 2021/1/13
Time: 17:12
To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
<title>插入记录实例</title>
</head>
<body>
<%
Connection con = null;
Statement stmt = null;
try{
Class.forName("com.mysql.jdbc.Driver");
con = DriverManager.getConnection("jdbc:mysql://localhost:3308/数据库名称","用户名","密码");
stmt = con.createStatement();
String sql = "insert into users(id,name,password) values(5,'hehe','asdf')";
stmt.execute(sql);
}
catch (ClassNotFoundException ex){
ex.printStackTrace();
}
catch (SQLException ex1){
ex1.printStackTrace();
}
finally {
try{
if(stmt!=null){
stmt.close();
stmt = null;
}
if(con!=null){
con.close();
con =null;
}
}
catch (SQLException ex){
ex.printStackTrace();