回 帖 发 新 帖 刷新版面

主题:最近装了mysql4.0.22版本出了问题。大家进来帮帮忙。谢谢了。

C:\Documents and Settings\zqc>cd c:\mysql\bin

C:\mysql\bin>use mysql
ERROR 1044: Access denied for user: '@localhost' to database 'mysql'
C:\mysql\bin>

以下是jsp页面连接mysql的时候的错误:
exception

javax.servlet.ServletException: Access denied for user: '@localhost' (Using password: YES)
    org.apache.jasper.runtime.PageContextImpl.doHandlePageException(PageContextImpl.java:825)
    org.apache.jasper.runtime.PageContextImpl.handlePageException(PageContextImpl.java:758)
    org.apache.jsp.test_jsp._jspService(test_jsp.java:94)
    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.sql.SQLException: Access denied for user: '@localhost' (Using password: YES)
    com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:2901)
    com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:773)
    com.mysql.jdbc.MysqlIO.doHandshake(MysqlIO.java:1258)
    com.mysql.jdbc.Connection.createNewIO(Connection.java:1699)
    com.mysql.jdbc.Connection.<init>(Connection.java:408)
    com.mysql.jdbc.NonRegisteringDriver.connect(NonRegisteringDriver.java:270)
    java.sql.DriverManager.getConnection(DriverManager.java:512)
    java.sql.DriverManager.getConnection(DriverManager.java:193)
    org.apache.jsp.test_jsp._jspService(test_jsp.java:56)
    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)


以下是我的测试连接代码:

<%@ page contentType="text/html;charset=GB2312" %>
<%@ page import="java.sql.*"%>
<html>
<head>
  <title>测试mysql</title>
</head>

<body>
<%
  try{
      Class.forName("com.mysql.jdbc.Driver").newInstance();
     }catch(Exception e){e.printStackTrace();}
      String url="jdbc:mysql://localhost/mysql?                                     user=root&password=801009&useUnicode=true&characterEncoding=GB2312";
      Connection conn=DriverManager.getConnection(url);
      Statement stmt=conn.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE,ResultSet.CONCUR_UPDATABLE);

      String sql="select * from testmysql";
      ResultSet rs=stmt.executeQuery(sql);
      while(rs.next()){%>

      你的第一个字段为:<%=rs.getString(1)%>
      你的第二个字段为:<%=rs.getString(2)%>

      <%}%>

      <%out.println("数据库操作成功!恭喜你!");%>
      <%
        rs.close();
        stmt.close();
        conn.close();
      %>


</body>
</html>





原来用的是4.0.16都没有什么问题的。可是后来卸载以后,直接装了4.0.22了。。就变成这样了。

回复列表 (共1个回复)

沙发

Access denied for user: '@localhost' 以上是说明你的mysql用户帐号不正确,
你可以用root 登录然后
use mysql;
select * from user看看现在有哪些用户,
然后grant all priviliges on *.*  to username@localhost with grant option新建一个用户,然后在jsp中把登录的用户名密码相应 的改一下即可.
本人的blog:http://www.tot.name/blog/

我来回复

您尚未登录,请登录后再回复。点此登录或注册