Unable to connect to tomcat MySQL database

Hey, I get this error:

com.mysql.jdbc.exceptions.jdbc4.MySQLNonTransientConnectionException:
Could not create connection to database server. 
Attempted reconnect 3 times. Giving up.

I am just trying to connect to a database. Using this code

<%@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/>");
}

%>

It finds the driver, but I get this error when I try to connect to the database.

I have this permission on catalina 50.local.policy

grant codeBase "file:/var/lib/tomcat6/WEB-INF/lib/-" {
  permission java.security.AllPermission;
};

Does anyone know why this error appears?

Edit: service mysql gives the following:

 * /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
+3
source share
2 answers

The driver is incorrect - use the class "com.mysql.jdbc.Driver".

JSP script code? Oh my ... this is not good.

But that is not the cause of your problem.

Did you have access rights to this username and password? The following are examples of steps:

  • root: mysql -h localhost -u root -p <ret> ; password = < >
  • " x;"
  • " p, 'q;"
  • " x. * 'x @%;"

p q, .

, ​​ 3306. "netstat -a" 3306.

MySQL .

, , Google. , .

, - . JSP - , , . .

. JSP .

  • MySQL ?
  • Java- ?
+2

MySQL 5,1 5,0, . - 5.1.

:)

0

Source: https://habr.com/ru/post/1722874/


All Articles