我的mysql版本是mysql-5.0.27-win32
驱动是mysql-connector-java-3.1.7-bin.jar
现在jsp老是连接不上mysql,tomat应该没有问题,是不是这个驱动不对?
等待中………………
驱动是mysql-connector-java-3.1.7-bin.jar
现在jsp老是连接不上mysql,tomat应该没有问题,是不是这个驱动不对?
等待中………………
调试欢乐多
你的jar放的位置对吗?
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="zhuang";
//密码
String userPasswd="6871311";
//数据库名
String dbName="chn";
//表名
String tableName="order1";
//联结字符串
String url="jdbc:mysql://localhost/"+dbName+"?user="+userName+"&password="+userPasswd;
Class.forName("com.mysql.jdbc.Driver").newInstance();
Connection connection=DriverManager.getConnection("jdbc:mysql://localhost:3306/test?user=zhuang&password=6871311&useUnicode=true&characterEncoding=gb2312");
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("name");
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();
%>
javax.servlet.ServletException: Access denied for user 'zhuang'@'localhost' to database 'test'
org.apache.jasper.runtime.PageContextImpl.doHandlePageException(PageContextImpl.java:848)
org.apache.jasper.runtime.PageContextImpl.handlePageException(PageContextImpl.java:781)
org.apache.jsp.mysql_jsp._jspService(org.apache.jsp.mysql_jsp:92)
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)mysql库我已经建立“chn”表为“order1”各位大侠帮我看看吧。
小弟万分感谢!!!!!!!!!