Question

I've deploy my .war file in Openshift with Tomcat 6 (JBoss EWS 1.0). Everything goes well until the app tries to connect with de MySQL DB.

I've search the info and I'm sure the info for my DB is:

  • HOST: 127.12.143.2
  • PORT: 3306
  • DB_NAME: redsocial

So my connection code is as follow:

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;

public class GestorDeConexiones {

private final static String DRIVER_CLASS_NAME = "com.mysql.jdbc.Driver";
private final static String DRIVER_URL = "jdbc:mysql://127.12.143.2:3306/";
private final static String USER = "xxxxxx";
private final static String PASSWORD = "xxxxxx";

static {

    try {
        Class.forName(DRIVER_CLASS_NAME);
    } catch (ClassNotFoundException e) {
        e.printStackTrace(System.err);
    }

}

private GestorDeConexiones() {}

public final static Connection getConnection() throws SQLException {
    return DriverManager.getConnection(DRIVER_URL, USER, PASSWORD);
}   
}

But always appears the same error: "No suitable driver found for jdbc:mysql://127.12.143.2:3306/redsocial"

When I deploy the app in Tomcat in a local way with "jdbc:mysql://localhost/redsocial" everything works perfectly.

¿Someone knows the solution?

Was it helpful?

Solution

Are you sure that you've added the jdbc driver (mysqlconnector jar) to your libraries that should be compiled with your code? Because, when you're running locally, the driver that is setup with your IDE will be used, but when you're deploying a .war file on a Tomcat server, this driver is not included by default. For example, in Netbeans: example of library
(source: evanaert.eu)

I'm suggesting this because locally everything works fine, but the problem occurs when deploying the .war file.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top