Can';t从tomcat连接到MySQL数据库
嘿,我得到了这个错误:Can';t从tomcat连接到MySQL数据库,mysql,jsp,connection,tomcat6,Mysql,Jsp,Connection,Tomcat6,嘿,我得到了这个错误: com.mysql.jdbc.exceptions.jdbc4.MySQLNonTransientConnectionException: Could not create connection to database server. Attempted reconnect 3 times. Giving up. 我只是想连接到数据库。使用此代码 <%@page import="java.sql.*"%> <% try{ // Class.for
com.mysql.jdbc.exceptions.jdbc4.MySQLNonTransientConnectionException:
Could not create connection to database server.
Attempted reconnect 3 times. Giving up.
我只是想连接到数据库。使用此代码
<%@page import="java.sql.*"%>
<%
try{
// Class.forName("com.mysql.jdbc.Driver");
Class.forName("org.gjt.mm.mysql.Driver");
out.println("found");
} catch (ClassNotFoundException ex){
out.println("Erro<br/>");
out.println(ex.toString());
} catch (Exception e){
out.println(e.toString());
}
Connection ocon;
try{
ocon = DriverManager.getConnection("jdbc:mysql://localhost/cpjcoimbra?autoReconnect=true", "*****", "*****"); //password matches
out.print("connected");
} catch (Exception e){
out.println(e.toString()+"<br/>");
}
%>
有人知道为什么会出现这个错误吗
编辑:
mysql服务状态提供以下信息:
* /usr/bin/mysqladmin Ver 8.42 Distrib 5.1.37, for debian-linux-gnu on i486
Copyright 2000-2008 MySQL AB, 2008 Sun Microsystems, Inc.
This software comes with ABSOLUTELY NO WARRANTY. This is free software,
and you are welcome to modify and redistribute it under the GPL license
Server version 5.1.37-1ubuntu5
Protocol version 10
Connection Localhost via UNIX socket
UNIX socket /var/run/mysqld/mysqld.sock
Uptime: 1 hour 32 min 21 sec
Threads: 1 Questions: 103 Slow queries: 0 Opens: 171 Flush tables: 1 Open tables: 41 Queries per second avg: 0.18
驱动程序错误-使用“com.mysql.jdbc.driver”类 JSP中的Scriptlet代码?哦,天哪,那不好 但这些不是你问题的原因 您是否授予该用户名和密码的权限?以下是示例步骤:
我将MySQL从5.1降级到5.0,现在一切正常。一定是5.1版本中的某种错误
很好,感谢您的帮助:)我尝试了这两个驱动程序,但两个驱动程序的错误都是一样的。我找到的唯一错误是:unix 2[ACC]流侦听4787/var/run/mysqld/mysqld.sock我尝试将连接更改为:4787,但仍然出现相同的错误。是的,我确实正确地创建了用户。那么他们在我提供的链接中引用的主机文件呢?你改变了吗?我在mysql-connector-java-5.1.6-bin.jar中找不到驱动程序,也找不到其他地方:\+1寻求帮助,虽然是的,我在几个小时前找到了,并将其添加到了hosts.allow中,但还是什么都没做,我开始绝望了:我只是在mysql-connector-java-5.1.6-bin.jar中查找com.mysql.jdbc.driver,我可以在我的机器上看到它。
* /usr/bin/mysqladmin Ver 8.42 Distrib 5.1.37, for debian-linux-gnu on i486
Copyright 2000-2008 MySQL AB, 2008 Sun Microsystems, Inc.
This software comes with ABSOLUTELY NO WARRANTY. This is free software,
and you are welcome to modify and redistribute it under the GPL license
Server version 5.1.37-1ubuntu5
Protocol version 10
Connection Localhost via UNIX socket
UNIX socket /var/run/mysqld/mysqld.sock
Uptime: 1 hour 32 min 21 sec
Threads: 1 Questions: 103 Slow queries: 0 Opens: 171 Flush tables: 1 Open tables: 41 Queries per second avg: 0.18