标题:[求助]关于连接mysql的问题
只看楼主
unbelievable
Rank: 1
等 级:新手上路
帖 子:8
专家分:0
注 册:2007-9-22
 问题点数:0 回复次数:6 
[求助]关于连接mysql的问题

怎么总是无法连接mySQL啊??

代码如下:
<%@ page contentType="text/html; charset=gb2312" language="java" import="java.sql.*" errorPage="" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<title>mysql连接数据库</title>
</head>

<body>


<%
Connection con = null;
Statement st = null;
ResultSet rs = null;
String dbuser="root";
String dbpswd="12345";
try {
try{Class.forName("com.mysql.jdbc.Driver").newInstance();}
catch (Exception e) {
out.println("Error1 :"+e.toString());
}
String url ="jdbc:mysql://localhost:3306/jnestore";
Connection conn= DriverManager.getConnection(url,dbuser,dbpswd);
st=conn.createStatement();
String sql="select * from catalog_items";
rs=st.executeQuery(sql);

while(rs.next())
{out.print("ok");}
}catch (Exception e) {
out.println("Error :"+e.toString());
}
finally {
try {
rs.close();
st.close();
con.close();
} catch (Exception ex) {
out.println("Error closing database");
} }%>

</body>
</html>

错误信息为:
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 /rcyjc/mysql.jsp at line 19

16: String dbuser="root";
17: String dbpswd="12345";
18: try {
19: try{Class.forName("com.mysql.jdbc.Driver").newInstance();}
20: catch (Exception e) {
21: out.println("Error1 :"+e.toString());
22: }


Stacktrace:
org.apache.jasper.servlet.JspServletWrapper.handleJspException(JspServletWrapper.java:524)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:417)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:320)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:266)
javax.servlet.http.HttpServlet.service(HttpServlet.java:803)


root cause

javax.servlet.ServletException: java.lang.NoClassDefFoundError: org/aspectj/lang/Signature
org.apache.jasper.runtime.PageContextImpl.doHandlePageException(PageContextImpl.java:850)
org.apache.jasper.runtime.PageContextImpl.handlePageException(PageContextImpl.java:779)
org.apache.jsp.rcyjc.mysql_jsp._jspService(mysql_jsp.java:104)
org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
javax.servlet.http.HttpServlet.service(HttpServlet.java:803)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:393)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:320)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:266)
javax.servlet.http.HttpServlet.service(HttpServlet.java:803)


root cause

java.lang.NoClassDefFoundError: org/aspectj/lang/Signature
java.lang.Class.forName0(Native Method)
java.lang.Class.forName(Unknown Source)
org.apache.jsp.rcyjc.mysql_jsp._jspService(mysql_jsp.java:72)
org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
javax.servlet.http.HttpServlet.service(HttpServlet.java:803)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:393)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:320)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:266)
javax.servlet.http.HttpServlet.service(HttpServlet.java:803)


note The full stack trace of the root cause is available in the Apache Tomcat/6.0.13 logs.

搜索更多相关主题的帖子: mysql 数据库 dtd java 
2007-09-23 12:40
evollock
Rank: 1
等 级:新手上路
帖 子:67
专家分:0
注 册:2007-7-4
得分:0 
com.mysql.jdbc.Driver

这句话错了,上面不都说了吗。。。
不是这样子写的吧,我记得mysql连接里面有mm,你自己baidu下吧
2007-09-23 17:46
无缘今生
Rank: 2
等 级:新手上路
威 望:3
帖 子:523
专家分:7
注 册:2007-6-25
得分:0 

回楼上:你所说的那种写法现在已经很少用了.现在一般都用楼主所写的.

回楼主:你把

try{Class.forName("com.mysql.jdbc.Driver").newInstance();}


改成

try{Class.forName("com.mysql.jdbc.Driver");}

试试.
不过你这样写应该也是没有问题的.你把MySQL的驱动配置好了没?在运行该程序前,你是否已经启动了mysql服务呢?
你仔细检查一下,你的语法是没有错的.

[此贴子已经被作者于2007-9-23 20:30:51编辑过]


时不再来!!!
2007-09-23 20:30
unbelievable
Rank: 1
等 级:新手上路
帖 子:8
专家分:0
注 册:2007-9-22
得分:0 
MySQL的驱动配置是什么东东??怎么配置???
2007-09-23 21:19
unbelievable
Rank: 1
等 级:新手上路
帖 子:8
专家分:0
注 册:2007-9-22
得分:0 
莫非就是所谓的mysql-connector-java-5.0.5-bin.jar????
2007-09-23 21:20
风月_无边
Rank: 16Rank: 16Rank: 16Rank: 16
等 级:版主
威 望:60
帖 子:2959
专家分:652
注 册:2007-1-19
得分:0 
驅動包肯定是要放到相應的目錄的﹗﹗

我的网站 http://www.
2007-09-24 18:15
xiaobohp
Rank: 1
等 级:新手上路
帖 子:64
专家分:0
注 册:2007-4-19
得分:0 
驱动就是JAVA和数据库访问必需有的一个连接器!我也是菜枭,不知道说的对不对

坚持, 只因不原放弃.
2007-09-25 20:01



参与讨论请移步原网站贴子:https://bbs.bccn.net/thread-172260-1-1.html




关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.020229 second(s), 7 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved