我只是想通过以下脚本将我的页面连接到 mysql 数据库。
// import java.sql.*;
try {
Class.forName("com.mysql.jdbc.Driver");
Connection con = DriverManager.getConnection("jdbc::mysql:://localhost::3306/schooldatabase","root","passwd");
Statement st=con.createStatement();
String sqlquery="INSERT INTO `schooldatabase`.`test` (`name`) VALUES ('anyname');";
con.commit();
}
catch(SQLException e){
}
但是会弹出以下错误消息。
type Exception report
message
description The server encountered an internal error () that prevented it from fulfilling this request.
exception
org.apache.jasper.JasperException: An exception occurred processing JSP page /final.jsp at line 20
18:
19: try {
20: Class.forName("com.mysql.jdbc.Driver");
21: Connection con = DriverManager.getConnection("jdbc::mysql:://localhost::3306/schooldatabase","root","passwd");
22: Statement st=con.createStatement();
23: String sqlquery="INSERT INTO `schooldatabase`.`test` (`name`) VALUES ('anyname');";
Stacktrace:
org.apache.jasper.servlet.JspServletWrapper.handleJspException(JspServletWrapper.java:568)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:455)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:390)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:334)
javax.servlet.http.HttpServlet.service(HttpServlet.java:722)
我的驱动程序名称是否适合 mysql 数据库?请指导我将 java 连接到数据库。