<%@ page language="java" contentType="text/html; charset=GBK"
pageEncoding="GBK"%>
<%@ page import="java.util.*" %>
<%@ page import="java.sql.*" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=GBK">
<title>Insert title here </title>
</head>
<body>
<font size=2>
<%
Connection conn = null;
Statement stmt=null;
String sql=null;
ResultSet rs=null;
DatabaseMetaData meta=null;
int ret;
try{
Class.forName("com.mysql.jdbc.Driver");
String strCon="jdbc:mysql://localhost:3306/test?user=root&password=123456";
conn= DriverManager.getConnection(strCon);
stmt = conn.createStatement();
sql="create database JspSamples";
ret = stmt.executeUpdate(sql);
sql="use JspSamples";
ret=stmt.executeUpdate(sql);
sql="CREATE TABLE customers("+
" Id int(6) unsigned NOT NULL auto_increment,"+
" Name varchar(20) default NULL,"+
" addTime timestamp NULL default NULL,"+
" Tel varchar(15) default NULL,"+
" Email varchar(20) default NULL"+
" PRIMARY KEY (Id)"+
")";
ret = stmt.executeUpdate(sql);
meta = conn.getMetaData();
}
catch (ClassNotFoundException e)
{
e.printStackTrace();
out.println(" <h1>无法找到数据库 </h1>");
}
catch(SQLException e1){
e1.printStackTrace();
out.println(" <h1>数据库操作失败 </h1>");
}
out.println(" <h1>新建数据库jspsamples成功 </h1>");
out.println(" <br>");
out.println("连接字" + meta.getURL());
out.println(" <br>");
out.println("数据库产品:" + meta.getDatabaseProductName());
out.println(" <br>");
out.println("数据库版本:" + meta.getDatabaseProductVersion());
out.println(" <br>");
out.println("驱动程序:" +meta.getDriverName());
out.println(" <br>");
out.println("驱动程序版本:" +meta.getDriverVersion());
stmt.close();
conn.close();
%>
</font>
</body>
</html>
出现的错如如下:
type Exception report
message
description The server encountered an internal error () that prevented it from fulfilling this request.
exception
javax.servlet.ServletException: org/aspectj/lang/Signature
org.apache.jasper.runtime.PageContextImpl.doHandlePageException(PageContextImpl.java:825)
org.apache.jasper.runtime.PageContextImpl.handlePageException(PageContextImpl.java:758)
org.apache.jsp.sqltest_jsp._jspService(sqltest_jsp.java:121)
org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:94)
javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:324)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:292)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:236)
javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
root cause
java.lang.NoClassDefFoundError: org/aspectj/lang/Signature
java.lang.Class.forName0(Native Method)
java.lang.Class.forName(Class.java:164)
org.apache.jsp.sqltest_jsp._jspService(sqltest_jsp.java:63)
org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:94)
javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:324)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:292)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:236)
javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
note The full stack trace of the root cause is available in the Apache Tomcat/5.0.28 logs.
--------------------------------------------------------------------------------
Apache Tomcat/5.0.28
不知道是哪里出了问题,由于刚开始学习,弄了好久都没弄懂,希望大家帮忙解决一下啊~~
--转自