I am coding a server at the moment I am developing it on a windows system with intellij idea and I want to run it on a Linux server(Debian).
On my windows PC all runs great I can connect my program to the SQL-server on my windows but when I "compile" the program and let it run on a Linux server I always get a java.sql.SQLException: No suitable driver found for jdbc:mysql/localhost:3306/...
exception and a java.lang.ClassNotFoundException: com.mysql.jdbc.Driver
exception.
My code
public class DataBaseHandler {
//Dieses Objekt stellt die Verbindung zur Datenbank da
private Connection connection;
private String dbName = "legitName";
private String hostName = "localhost:3306";
private String loginName = "legitName";
private String pw = "legitPW";
private Controller c;
public DataBaseHandler(Controller c){
this.c = c;
connectToDb();
}
//Methode um eine Verbindung mit der Datenbank herzustellen
private void connectToDb(){
try {
Class.forName("com.mysql.jdbc.Driver");
} catch (ClassNotFoundException e) {
System.out.println("rude german words here");
e.printStackTrace();
}
String connectCommand = "jdbc:mysql://"+hostName+"/"+dbName+""+"?useSSL=false&user="+loginName+"&password="+pw;
try {
connection = DriverManager.getConnection(connectCommand);
} catch (SQLException e) {
e.printStackTrace();
}
//tstQuery();
}
so as already mentioned this runs perfect on my windows and I can even execute the "testQuery()" method which gives me back some resluts but on my server the line Class.forName("com.mysql.jdbc.Driver").newInstance();
causes the "ClassNotFoundException" and the DriverManager.getConnection()
line causes the SQLexception.
In Intellij under project structure I added the
mysql-connector-java-5.1.41-bin.jar
to the Classpath under SDK and also to the Global Libaries.
The Linux server is also running MySql DB.