日期:2014-05-18  浏览次数:20679 次

连接不到mysql,求教
mm.mysql那个驱动已经弄好了,数据库、用户名、密码可以肯定没有错

<%@   page   contentType= "text/html;charset=gb2312 "   %>
<%@   page   import= "java.sql.* "%>
<html>
<head>
<title> lol </title>
</head>
<body>

<%
try   {
Class.forName( "org.gjt.mm.mysql.Driver ").newInstance();
}
catch   (Exception   E)   {
out.println( "出错了:( ");
}
String   url= "jdbc:mysql://localhost:80:testdb ";  
String   user= "root ";  
String   password= " ";  


try
{
Connection   conn=   DriverManager.getConnection(url,user,password);
}
catch(SQLException   e1)
{
out.print( "连接失败 ");
}
%>

</body>
</html>

测试后,显示‘连接失败’。请问问题出在哪里?

------解决方案--------------------
DriverManager.getConnection写的也有问题,你这个貌似oracle的连接
------解决方案--------------------
Connection conn= DriverManager.getConnection(url,user,password);
}
这一句有问题是肯定的了?
你的端口号是不是不对
------解决方案--------------------
String url= "jdbc:mysql://localhost:3306/testdb ";
你再试一下,尤其是你要修改testdb前面可不是什么 ": "符号哦!
------解决方案--------------------
mysql-connector-java-3.x.x-bin.jar是mysql连接的驱动程序库。
Mysql的官方网站上有的。呵呵。
还有这种错误在tomcat的错误提示信息中能看到的,如果使用Tomcat服务器的话。
------解决方案--------------------
很多地方有下载的 下好后放在D:\Tomcat\common\lib
我的代码 给你参考~!
<%
Connection con=null;
try{
Class.forName( "org.gjt.mm.mysql.Driver ");
con=DriverManager.getConnection( "jdbc:mysql://127.0.0.1:3306/peter ", "root ", "root ");
}catch (Exception e) {
e.printStackTrace();
System.exit(-1);
}