Hei Community ,
leider funktioniert meine Connection zu meinem SQL Server nicht , er sagt mir immer entweder :" Unknow database ... " oder ,"com.mysql.jdbc.JDBC4Connection cannot be cast to main.Connection". Doch beide Database gibt es.
Ich hoffe ihr könnt mir helfen.
Klasse :
Java Version : 1.8
Server: MySQL Community Server (GPL)
Version: 5.7.15
leider funktioniert meine Connection zu meinem SQL Server nicht , er sagt mir immer entweder :" Unknow database ... " oder ,"com.mysql.jdbc.JDBC4Connection cannot be cast to main.Connection". Doch beide Database gibt es.
Ich hoffe ihr könnt mir helfen.
Code:
publicConnectioncon(){
try{
Class.forName("com.mysql.jdbc.Driver").newInstance();
StringconnectionCommand="jdbc:mysql://localhost:3306/newSch?user=root&password=password&useSSL=false";
connection=(Connection)DriverManager.getConnection(connectionCommand);
returnconnection;
}
catch(Exceptionex){
System.out.println("A problem has appered with the Mysql.");
System.out.println(ex.getMessage());
returnnull;
}
}
Klasse :
Code:
package main;
import java.sql.DriverManager;
publicclassConnection{
Connectionconnection;
publicConnection(){
}
publicbooleanconnectToMysql(Stringhost,Stringdatabase,Stringuser,Stringpasswd){
try{
Class.forName("com.mysql.jdbc.Driver").newInstance();
StringconnectionCommand="jdbc:mysql://"+host+"/"+database+"?user="+user+"&password="+passwd+"&useSSL=false";
connection=(Connection)DriverManager.getConnection(connectionCommand);
returntrue;
}
catch(Exceptionex){
System.out.println(ex.getMessage());
returnfalse;
}
}
/*
* Don't forget to change the connectionCommand if there is a modifaktion.
* Check connectToMysql to compare.
*/
publicConnectioncon(){
try{
Class.forName("com.mysql.jdbc.Driver").newInstance();
StringconnectionCommand="jdbc:mysql://localhost:3306/newSch?user=root&password=password&useSSL=false";
connection=(Connection)DriverManager.getConnection(connectionCommand);
returnconnection;
}
catch(Exceptionex){
System.out.println("A problem has appered with the Mysql.");
System.out.println(ex.getMessage());
returnnull;
}
}
}
Java Version : 1.8
Server: MySQL Community Server (GPL)
Version: 5.7.15
Zuletzt bearbeitet: