tomcat cannot connect to mysql

Hey, I’m getting this error:

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

I’m just trying to connect to the database. With 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 does find the driver but I’m getting that 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;
};

Anyone has any idea why that error shows up?

Edit: service mysql status gives this:

 * /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

Smoking itself does not directly kill the environment, but it can contribute to environmental problems in several ways. One significant way is through the production and disposal of cigarette butts, which are the most commonly littered item worldwide. Cigarette filters are not biodegradable, and they can take many years to decompose. This litter can harm wildlife and contribute to pollution of waterways and other ecosystems.

Smoking also contributes to air pollution, which can harm both the environment and human health. Smoking releases many harmful chemicals into the air, including carbon monoxide, nitrogen oxides, and volatile organic compounds, which can contribute to smog and acid rain. Secondhand smoke can also be harmful to others and contribute to indoor air pollution.

Raja muneeb : Global Wholesale And Marketing Pvt Ltd.

Web Development courses in islamabad cover vast field of technology, and there are many educational courses available in Career Vision Institute. The specific course you choose will depend on your interests and goals within the field of technology. Here are some examples of technology educational courses that you might find helpful:

Computer Science: This course is the study of computers and computational systems. It covers a wide range of topics, including programming, algorithms, data structures, computer organization, and more.

Information Technology: This course focuses on the use of technology in business and other organizations. It covers topics such as database management, networking, cybersecurity, and software development.

SEO course in Rawalpindi starting next month with discounted free admission fee option :

One of the primary reasons why many small to medium businesses choose to go with an SEO specialist to help them is that the SEO Course Benefits

they can get from such training is something that cannot be beaten. The reason for this is simple. With such a great deal of information available on the internet, it is very easy to find a course or tutorial that will benefit you

Data Science: This course is the study of how to extract insights and knowledge from data using statistical and computational methods. It covers topics such as machine learning, data mining, and big data analytics.

Web Development: This course teaches you how to design and develop websites using programming languages such as HTML, CSS, and JavaScript.

Mobile App Development: This course focuses on the development of mobile applications for iOS and Android devices.

These are just a few examples of the many technology educational courses available. It’s important to research your options and choose a course that aligns with your interests and career goals within the field of technology.

Author : Arslan Hussain, Careervision Institute Islamabad.

Leave a Comment

Your email address will not be published. Required fields are marked *

Shopping Cart