package conexion;
import com.mysql.jdbc.*;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
import java.sql.Statement;
public class conexion {
Connection co;
Statement stm;
//jdbc:mysql://localhost:3306/java?zeroDateTimeBehavior=convertToNull [root on Default schema]
public static Connection iniciarConnection(){
try {
Class.forName("com.mysql.jdbc.Driver");
Connection co= DriverManager.getConnection("jdbc:mysql//localhost:3306/java", "root", "");
Statement stm = co.createStatement();
System.out.println("Conectado correctamente a la Base de Datos");
return co;
} catch (ClassNotFoundException e) {
System.out.println("Clase no encontrada: "+e);
} catch (SQLException e) {
System.out.println("Error de conexion: "+e);
} catch (Exception e) {
System.out.println("Error desconocido: "+e);
}
return null;
}
}
Aqui os pongo el OutPut:
Error de conexion: java.sql.SQLException: No suitable driver found for jdbc:mysql//localhost:3306/java