Topic: jdbc 连接mysql报错,望高手指点 |
Print this page |
1.jdbc 连接mysql报错,望高手指点 | Copy to clipboard |
Posted by: fly21 Posted on: 2005-03-11 10:41 我的连接代码: <%@page contentType="text/html;charset=GB2312"%> <%@page import="java.sql.*,java.lang.*"%> <%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%> <html> <body> <% try{ Class.forName("com.mysql.jdbc.Driver").newInstance(); }catch(ClassNotFoundException e){} String url="jdbc:mysql://localhost/test?user=root&password=''"; Connection conn=DriverManager.getConnection(url); Statement stmt=conn.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE,ResultSet.CONCUR_UPDATABLE); String sql="select * from test"; ResultSet rs=stmt.executeQuery(sql); while(rs.next()){%> <%="数据库操作成功,恭喜你!"%> <%=rs.getString(1)%> <%=rs.getString(2)%> <%}%> <% rs.close(); stmt.close(); conn.close(); %> </body> </html> 显示信息: type Exception report message description The server encountered an internal error () that prevented it from fulfilling this request. exception javax.servlet.ServletException: Access denied for user: 'root@localhost' (Using password: YES) org.apache.jasper.runtime.PageContextImpl.doHandlePageException(PageContextImpl.java:846) org.apache.jasper.runtime.PageContextImpl.handlePageException(PageContextImpl.java:779) org.apache.jsp.connect_jsp._jspService(org.apache.jsp.connect_jsp:92) org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:99) javax.servlet.http.HttpServlet.service(HttpServlet.java:802) org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:325) org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:291) org.apache.jasper.servlet.JspServlet.service(JspServlet.java:241) javax.servlet.http.HttpServlet.service(HttpServlet.java:802) root cause java.sql.SQLException: Access denied for user: 'root@localhost' (Using password: YES) com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:2847) com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:750) com.mysql.jdbc.MysqlIO.doHandshake(MysqlIO.java:1205) com.mysql.jdbc.Connection.createNewIO(Connection.java:1768) com.mysql.jdbc.Connection.<init>(Connection.java:430) com.mysql.jdbc.NonRegisteringDriver.connect(NonRegisteringDriver.java:268) java.sql.DriverManager.getConnection(Unknown Source) java.sql.DriverManager.getConnection(Unknown Source) org.apache.jsp.connect_jsp._jspService(org.apache.jsp.connect_jsp:57) org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:99) javax.servlet.http.HttpServlet.service(HttpServlet.java:802) org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:325) org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:291) org.apache.jasper.servlet.JspServlet.service(JspServlet.java:241) javax.servlet.http.HttpServlet.service(HttpServlet.java:802) note The full stack trace of the root cause is available in the Apache Tomcat/5.5.8 logs. |
2.Re:jdbc 连接mysql报错,望高手指点 [Re: fly21] | Copy to clipboard |
Posted by: 九佰 Posted on: 2005-03-11 12:56 你的mysql的root用户密码不对 |
3.Re:jdbc 连接mysql报错,望高手指点 [Re: fly21] | Copy to clipboard |
Posted by: fly21 Posted on: 2005-03-11 13:23 密码为空 |
4.Re:jdbc 连接mysql报错,望高手指点 [Re: fly21] | Copy to clipboard |
Posted by: javajin Posted on: 2005-03-14 11:43 你的写法不对 应该是: String url="jdbc:mysql://localhost/test?user=root&password="; 去掉那个单引号,单引号不是你的密码 |
5.Re:jdbc 连接mysql报错,望高手指点 [Re: fly21] | Copy to clipboard |
Posted by: fly21 Posted on: 2005-03-14 13:46 谢谢javajin!去掉那个单引号后问题解决,终于连上 |
Powered by Jute Powerful Forum® Version Jute 1.5.6 Ent Copyright © 2002-2021 Cjsdn Team. All Righits Reserved. 闽ICP备05005120号-1 客服电话 18559299278 客服信箱 714923@qq.com 客服QQ 714923 |