1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37
|
public class TestConnectionJDBC {
import java.sql.*;
import javax.swing.JOptionPane;
public TestConnectionJDBC() {
}
public static void main(String[] args) {
Connection connexion = null;
try{
Class.forName("com.mysql.jdbc.Driver");
connexion = DriverManager.getConnection("jdbc:mysql:///test");
JOptionPane.showMessageDialog(null, "Connexion Ok");
}
catch(ClassNotFoundException ex){
JOptionPane.showMessageDialog(null, "Classe introuvable " + ex.getMessage());
}
catch(SQLException ex){
JOptionPane.showMessageDialog(null,"Connexion impossible : " + ex.getMessage());
}
finally{
try{
if(connexion != null)
connexion.close();
}
catch(SQLException ex){
ex.printStackTrace();
}
}
System.exit(0);
}
} |