JSP连接MYSQL的问题

来源:百度知道 编辑:UC知道 时间:2024/07/06 00:04:11
编写JSP代码连接MYSQL时,出现握手错误?
我用的MYSQL4.1+RESIN2.1.9+JDK1.4.2
JDBC驱动用的2.0.14
代码编写如下MYSQL打开且已建立数据库)
<%@page language="java" import="java.sql.*" contentType="text/html; charset=gb2312" %>
<%
String ls_username = "root"; //数据库用户名
String ls_password = "7230109"; //密码
String ls_server = "localhost";
String ls_dbname = "oa"; //数据库名称
Connection con = null;
try
{
//注册JDBC连接驱动
Class.forName("com.mysql.jdbc.Driver";
//与数据库建立连接
con = DriverManager.getConnection("jdbc:mysql://"+ls_server+"/"+ls_dbname,ls_username,ls_password);
}
catch(Exception e)
{
System.out.println(e.toString());
}
%>

<html>
<head>
<title>测试数据库连接</title>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312"&g

没碰到过,我找到了3种解决办法
1.换一个新版本的驱动看看
Class.forName("org.gjt.mm.mysql.Driver") 换成
Class.forName("com.mysql.jdbc.Driver")
2.localhost换成127.0.0.1:3306
3.在mysql命令行中输入
set password for <username>@<servername> = old_password('<password>');
像你的可以这么输入试试
set password for root@localhost= old_password('7230109');
再没有用的话我也没发现什么方法了

Class.forName("com.mysql.jdbc.Driver";

这句后面的括号呢?