Connection Class:
public class ConectaSiscart {
static Connection connection = null;
Statement stm = null;
static String serverName = \"
I think I figured out what's happening. When you call DriverManager.getConnection, it will try all the available drivers one by one until one succeeds. When it calls connect on a driver, it can return null if it's the wrong driver, throw an exception if it failed, or return a Connection object if it succeeds. When all the drivers fail, DriverManager throws the first exception it got, if any, or else creates and throws a "No suitable driver found" exception.
This is probably what's happening in your case:
- DriverManager is trying the sqlite driver first; it is supposed to return null because it's the wrong driver for the url, but instead it is throwing an exception (this is a bug in the sqlite driver implementation!)
- next, DriverManager is trying the mysql driver, which fails to connect for some other reason (for example, server not running, or wrong password)
- DriverManager sees that all the drivers failed to connect, so it throws the first exception it got, which is the one from sqlite (due to that implementation bug)
What you can do:
- Remove the sqlite driver temporarily from the classpath to solve the mysql connection problem
- Better, use a DataSource instead of DriverManager. Mysql example:
MysqlDataSource ds = new MysqlDataSource();
ds.setServerName(serverName);
ds.setDatabaseName(mydatabase);
ds.setUser(username);
ds.setPassword(password);
connection = ds.getConnection();
Or you can use a database library to handle it for you