Topic: JSP连接mysql数据库的问题?那位大哥给看看? |
Print this page |
1.JSP连接mysql数据库的问题?那位大哥给看看? | Copy to clipboard |
Posted by: zhupan Posted on: 2005-11-12 13:31 jsp代码如下: <%@ page contentType="text/html; charset=gb2312" %> <%@ page language="java" %> <%@ page import="com.mysql.jdbc.Driver" %> <%@ page import="java.sql.*" %> <% //驱动程序名 String driverName="com.mysql.jdbc.Driver"; //数据库用户名 String userName="zhupan"; //密码 String userPasswd="zhupan"; //数据库名 String dbName="shujuku"; //表名 String tableName="biao"; //联结字符串 String url="jdbc:mysql://localhost/"+dbName+"?user="+userName+"&password="+userPasswd; Class.forName("com.mysql.jdbc.Driver").newInstance(); Connection connection=DriverManager.getConnection(url); Statement statement = connection.createStatement(); String sql="SELECT * FROM "+tableName; ResultSet rs = statement.executeQuery(sql); //获得数据结果集合 ResultSetMetaData rmeta = rs.getMetaData(); //确定数据集的列数,亦字段数 int numColumns=rmeta.getColumnCount(); // 输出每一个数据值 out.print("id"); out.print("|"); out.print("num"); out.print("<br>"); while(rs.next()) { out.print(rs.getString(1)+" "); out.print("|"); out.print(rs.getString(2)); out.print("<br>"); } out.print("<br>"); out.print("数据库操作成功,恭喜你"); rs.close(); statement.close(); connection.close(); %> 错误如下: type Exception report message description The server encountered an internal error () that prevented it from fulfilling this request. exception javax.servlet.ServletException: Invalid authorization specification, message from server: "Access denied for user 'zhupan'@'localhost' (using password: YES)" org.apache.jasper.runtime.PageContextImpl.doHandlePageException(PageContextImpl.java:848) org.apache.jasper.runtime.PageContextImpl.handlePageException(PageContextImpl.java:781) org.apache.jsp.test4_jsp._jspService(org.apache.jsp.test4_jsp:134) org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:97) javax.servlet.http.HttpServlet.service(HttpServlet.java:802) org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:322) 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: Invalid authorization specification, message from server: "Access denied for user 'zhupan'@'localhost' (using password: YES)" com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:1905) com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:1831) com.mysql.jdbc.MysqlIO.secureAuth411(MysqlIO.java:2389) com.mysql.jdbc.MysqlIO.doHandshake(MysqlIO.java:757) com.mysql.jdbc.Connection.createNewIO(Connection.java:1654) com.mysql.jdbc.Connection.<init>(Connection.java:432) com.mysql.jdbc.NonRegisteringDriver.connect(NonRegisteringDriver.java:400) java.sql.DriverManager.getConnection(Unknown Source) java.sql.DriverManager.getConnection(Unknown Source) org.apache.jsp.test4_jsp._jspService(org.apache.jsp.test4_jsp:80) org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:97) javax.servlet.http.HttpServlet.service(HttpServlet.java:802) org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:322) 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.9 logs. 请问下是什么问题? |
2.Re:JSP连接mysql数据库的问题?那位大哥给看看? [Re: zhupan] | Copy to clipboard |
Posted by: zhupan Posted on: 2005-11-12 15:13 问题已经解决 驱动版本太低了 换了一个新的解决问题 |
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 |