Boa tarde pessoal,
Estou tentando conectar com o MySQL e está gerando o seguinte erro:
java.lang.ClassNotFoundException: com.mysql.jdbc.Driver
at java.net.URLClassLoader$1.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClassInternal(Unknown Source)
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Unknown Source)
at br.com.avanti.sia.entidade.integracao.MySQL.connect(MySQL.java:33)com.mysql.jdbc.Driver
at br.com.avanti.sia.entidade.integracao.MySQL.main(MySQL.java:60)
Segue o meu código:
[code]import java.sql.DriverManager;
import java.sql.SQLException;
import java.sql.Connection;
public class MySQL {
private String host;
private String user;
private String pass;
private String database;
public Connection c;
public MySQL( String host, String database, String user, String pass ) {
this.pass = pass;
this.user = user;
this.host = host;
this.database = database;
}
public boolean connect() {
boolean isConnected = false;
String url;
url = "jdbc:mysql://"+this.host+"/"
+this.database+"?"
+"user="+this.user
+"&password="+this.pass;
try {
Class.forName("com.mysql.jdbc.Driver").newInstance();
System.out.println(url);
this.c = DriverManager.getConnection(url);
isConnected = true;
} catch( SQLException e ) {
e.printStackTrace();
System.out.println(e.getMessage());
isConnected = false;
} catch ( ClassNotFoundException e ) {
e.printStackTrace();
System.out.println(e.getMessage());
isConnected = false;
} catch ( InstantiationException e ) {
e.printStackTrace();
System.out.println(e.getMessage());
isConnected = false;
} catch ( IllegalAccessException e ) {
e.printStackTrace();
System.out.println(e.getMessage());
isConnected = false;
}
return isConnected;
}
public static void main (String [] args) {
MySQL db = new MySQL("xx","xx","xx","xx");
if ( db.connect() ) {
System.out.println("Conectado!");
};
}
}[/code]
Agradeço a ajuda.