我正在学习 JSP,我想使用 JSP 在 mysql 中创建一个表。我有以下代码。
<%@ page contentType="text/html;charset=UTF-8" %>
<%@ page errorPage="error.jsp" %>
<%@ page import="java.sql.*" %>
<html>
<head>
<title>MySQL Database creation</title>
<style>
{ font-size: 12px; font-family: Verdana }
</style>
</head>
<body>
<h2>Creation of a books database</h2>
<jsp:declaration>
Statement stmt;
Connection con;
String url = "jdbc:mysql://localhost:3306/";
</jsp:declaration>
<jsp:scriptlet><![CDATA[
Class.forName("com.mysql.jdbc.Driver");
con = DriverManager.getConnection(url, "root", "");
stmt = con.createStatement();
stmt.executeUpdate("CREATE DATABASE books");
con.close();
]]></jsp:scriptlet>
</body>
</html>
我的error.jsp页面是
<%@ page contentType="text/html" pageEncoding="UTF-8"%>
<%@ page isErrorPage="true" %>
<html>
<head>
<title>Error page</title>
<style>
{ font-size: 12px; font-family: Verdana }
</style>
</head>
<body>
<h2>Error occured!</h2>
<p>Message
<jsp:expression>
exception.getMessage()
</jsp:expression>
</p>
</body>
</html>
当我运行它时,它被重定向到错误页面并获得如下输出:
发生了错误!消息 com.mysql.jdbc.Driver
我哪里错了?