Probleme driver mysql non trouvé /java
Résolu
astrocybernaute
Messages postés
80
Date d'inscription
Statut
Membre
Dernière intervention
-
manotexe -
manotexe -
Bonjour,
je suis entrain de developper une application sous java et jai besoin d'une connexion base de données
alors jai choisi mysql connector/j je l'ai mis dans le repertoire jar de mon eclipse et je lai ajouté depui les proprietés de mon projet
j'ai aussi ajouté le chemin dans le PATH
j'ai installé easyphp et crée ma base de donné (DMN) et une table user
mais dés que je lance ma fenetre j'ai une erreur : "driver non trouvé"
voici mon code:
package src;
import java.awt.event.*;
import java.sql.*;
import javax.swing.*;
import com.cloudgarden.layout.*;
public class LoginJFrame extends javax.swing.JFrame {
private JButton OK;
private JLabel jLabelTitre;
private JLabel jLabelMDP;
private JLabel jLabelNom;
private JTextField mdp;
private JTextField name;
Connection connection = null;
ResultSet rs = null;
{
//Set Look & Feel
try {
javax.swing.UIManager.setLookAndFeel(javax.swing.UIManager.getSystemLookAndFeelClassName());
} catch(Exception e) {
e.printStackTrace();
}
}
public static void main(String[] args) {
SwingUtilities.invokeLater(new Runnable() {
public void run() {
LoginJFrame inst = new LoginJFrame();
inst.setLocationRelativeTo(null);
inst.setVisible(true);
}
});
}
public LoginJFrame() {
super();
///connnexion a la bdd
try
{
// Chargement des drivers SQL
Class.forName ("com.mysql.Driver").newInstance();
}
catch (ClassNotFoundException a)
{
System.out.println ("Driver non trouve");
}
catch (Exception b)
{
System.out.println ("Problème sur chargement de driver JDBC");
}
try
{
// Etablissement de la connexion avec la base
connection = DriverManager.getConnection ("jdbc:mysql://localhost/DMN", "root", "");
}
catch (SQLException c)
{
System.out.println ("Connexion refusée ou base inconnue");
}
catch (Exception d)
{
System.out.println ("Problème sur connexion");
}
initGUI();
}
private void initGUI() {
try {
AnchorLayout thisLayout = new AnchorLayout();
getContentPane().setLayout(thisLayout);
setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
this.setName("frameLogin");
this.setTitle("Login");
{
jLabelTitre = new JLabel();
getContentPane().add(jLabelTitre, new AnchorConstraint(65, 567, 196, 121, AnchorConstraint.ANCHOR_REL, AnchorConstraint.ANCHOR_REL, AnchorConstraint.ANCHOR_REL, AnchorConstraint.ANCHOR_REL));
jLabelTitre.setText("Identifiez vous");
jLabelTitre.setPreferredSize(new java.awt.Dimension(116, 23));
jLabelTitre.setFont(new java.awt.Font("Agency FB",1,18));
}
{
jLabelMDP = new JLabel();
getContentPane().add(jLabelMDP, new AnchorConstraint(530, 336, 627, 78, AnchorConstraint.ANCHOR_REL, AnchorConstraint.ANCHOR_REL, AnchorConstraint.ANCHOR_REL, AnchorConstraint.ANCHOR_REL));
jLabelMDP.setText("Mot de passe");
jLabelMDP.setPreferredSize(new java.awt.Dimension(67, 16));
}
{
jLabelNom = new JLabel();
getContentPane().add(jLabelNom, new AnchorConstraint(384, 294, 469, 78, AnchorConstraint.ANCHOR_REL, AnchorConstraint.ANCHOR_REL, AnchorConstraint.ANCHOR_REL, AnchorConstraint.ANCHOR_REL));
jLabelNom.setText("Nom");
jLabelNom.setPreferredSize(new java.awt.Dimension(56, 14));
}
{
mdp = new JPasswordField();
getContentPane().add(mdp, new AnchorConstraint(536, 763, 657, 355, AnchorConstraint.ANCHOR_REL, AnchorConstraint.ANCHOR_REL, AnchorConstraint.ANCHOR_REL, AnchorConstraint.ANCHOR_REL));
mdp.setPreferredSize(new java.awt.Dimension(106, 20));
}
{
name = new JTextField();
getContentPane().add(name, new AnchorConstraint(366, 763, 481, 355, AnchorConstraint.ANCHOR_REL, AnchorConstraint.ANCHOR_REL, AnchorConstraint.ANCHOR_REL, AnchorConstraint.ANCHOR_REL));
name.setPreferredSize(new java.awt.Dimension(106, 19));
}
{
OK = new JButton();
getContentPane().add(OK, new AnchorConstraint(742, 963, 900, 678, AnchorConstraint.ANCHOR_REL, AnchorConstraint.ANCHOR_REL, AnchorConstraint.ANCHOR_REL, AnchorConstraint.ANCHOR_REL));
OK.setText("OK");
OK.setPreferredSize(new java.awt.Dimension(74, 26));
OK.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent arg0) {
// TODO verifier le mdp
NewSwingApp N=new NewSwingApp();
N.setVisible(true);
dispose();
}
});
}
//pack();
/// Exécution des requêtes
try
{
Statement stmt = connection.createStatement();
String requete = null;
requete = "SELECT nom_user, mdp From user";
rs = stmt.executeQuery(requete);
while (rs.next())
{
// Affichage les resultats de la requete SQL
name.setText(rs.getString(1));
}
}
catch (Exception d)
{
System.out.println ("Problème la requete");
}
this.setSize(268, 195);
} catch (Exception e) {
e.printStackTrace();
}
}
}
j'apprécierai vraiment votre aide pcq ca fait plus de deux jour que je suis bloquée dans ce probleme
merci d'avance
je suis entrain de developper une application sous java et jai besoin d'une connexion base de données
alors jai choisi mysql connector/j je l'ai mis dans le repertoire jar de mon eclipse et je lai ajouté depui les proprietés de mon projet
j'ai aussi ajouté le chemin dans le PATH
j'ai installé easyphp et crée ma base de donné (DMN) et une table user
mais dés que je lance ma fenetre j'ai une erreur : "driver non trouvé"
voici mon code:
package src;
import java.awt.event.*;
import java.sql.*;
import javax.swing.*;
import com.cloudgarden.layout.*;
public class LoginJFrame extends javax.swing.JFrame {
private JButton OK;
private JLabel jLabelTitre;
private JLabel jLabelMDP;
private JLabel jLabelNom;
private JTextField mdp;
private JTextField name;
Connection connection = null;
ResultSet rs = null;
{
//Set Look & Feel
try {
javax.swing.UIManager.setLookAndFeel(javax.swing.UIManager.getSystemLookAndFeelClassName());
} catch(Exception e) {
e.printStackTrace();
}
}
public static void main(String[] args) {
SwingUtilities.invokeLater(new Runnable() {
public void run() {
LoginJFrame inst = new LoginJFrame();
inst.setLocationRelativeTo(null);
inst.setVisible(true);
}
});
}
public LoginJFrame() {
super();
///connnexion a la bdd
try
{
// Chargement des drivers SQL
Class.forName ("com.mysql.Driver").newInstance();
}
catch (ClassNotFoundException a)
{
System.out.println ("Driver non trouve");
}
catch (Exception b)
{
System.out.println ("Problème sur chargement de driver JDBC");
}
try
{
// Etablissement de la connexion avec la base
connection = DriverManager.getConnection ("jdbc:mysql://localhost/DMN", "root", "");
}
catch (SQLException c)
{
System.out.println ("Connexion refusée ou base inconnue");
}
catch (Exception d)
{
System.out.println ("Problème sur connexion");
}
initGUI();
}
private void initGUI() {
try {
AnchorLayout thisLayout = new AnchorLayout();
getContentPane().setLayout(thisLayout);
setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
this.setName("frameLogin");
this.setTitle("Login");
{
jLabelTitre = new JLabel();
getContentPane().add(jLabelTitre, new AnchorConstraint(65, 567, 196, 121, AnchorConstraint.ANCHOR_REL, AnchorConstraint.ANCHOR_REL, AnchorConstraint.ANCHOR_REL, AnchorConstraint.ANCHOR_REL));
jLabelTitre.setText("Identifiez vous");
jLabelTitre.setPreferredSize(new java.awt.Dimension(116, 23));
jLabelTitre.setFont(new java.awt.Font("Agency FB",1,18));
}
{
jLabelMDP = new JLabel();
getContentPane().add(jLabelMDP, new AnchorConstraint(530, 336, 627, 78, AnchorConstraint.ANCHOR_REL, AnchorConstraint.ANCHOR_REL, AnchorConstraint.ANCHOR_REL, AnchorConstraint.ANCHOR_REL));
jLabelMDP.setText("Mot de passe");
jLabelMDP.setPreferredSize(new java.awt.Dimension(67, 16));
}
{
jLabelNom = new JLabel();
getContentPane().add(jLabelNom, new AnchorConstraint(384, 294, 469, 78, AnchorConstraint.ANCHOR_REL, AnchorConstraint.ANCHOR_REL, AnchorConstraint.ANCHOR_REL, AnchorConstraint.ANCHOR_REL));
jLabelNom.setText("Nom");
jLabelNom.setPreferredSize(new java.awt.Dimension(56, 14));
}
{
mdp = new JPasswordField();
getContentPane().add(mdp, new AnchorConstraint(536, 763, 657, 355, AnchorConstraint.ANCHOR_REL, AnchorConstraint.ANCHOR_REL, AnchorConstraint.ANCHOR_REL, AnchorConstraint.ANCHOR_REL));
mdp.setPreferredSize(new java.awt.Dimension(106, 20));
}
{
name = new JTextField();
getContentPane().add(name, new AnchorConstraint(366, 763, 481, 355, AnchorConstraint.ANCHOR_REL, AnchorConstraint.ANCHOR_REL, AnchorConstraint.ANCHOR_REL, AnchorConstraint.ANCHOR_REL));
name.setPreferredSize(new java.awt.Dimension(106, 19));
}
{
OK = new JButton();
getContentPane().add(OK, new AnchorConstraint(742, 963, 900, 678, AnchorConstraint.ANCHOR_REL, AnchorConstraint.ANCHOR_REL, AnchorConstraint.ANCHOR_REL, AnchorConstraint.ANCHOR_REL));
OK.setText("OK");
OK.setPreferredSize(new java.awt.Dimension(74, 26));
OK.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent arg0) {
// TODO verifier le mdp
NewSwingApp N=new NewSwingApp();
N.setVisible(true);
dispose();
}
});
}
//pack();
/// Exécution des requêtes
try
{
Statement stmt = connection.createStatement();
String requete = null;
requete = "SELECT nom_user, mdp From user";
rs = stmt.executeQuery(requete);
while (rs.next())
{
// Affichage les resultats de la requete SQL
name.setText(rs.getString(1));
}
}
catch (Exception d)
{
System.out.println ("Problème la requete");
}
this.setSize(268, 195);
} catch (Exception e) {
e.printStackTrace();
}
}
}
j'apprécierai vraiment votre aide pcq ca fait plus de deux jour que je suis bloquée dans ce probleme
merci d'avance
A voir également:
- Probleme driver mysql non trouvé /java
- Waptrick java football - Télécharger - Jeux vidéo
- Jeux java itel - Télécharger - Jeux vidéo
- Eclipse java - Télécharger - Langages
- Realtek audio driver - Télécharger - Pilotes & Matériel
- Java apk - Télécharger - Langages
dis j'utilise eclipse galileo et mysql et j'arrive pas à me connecter à mysql en plus je voufrais savoir si dans ton programme tu fais des etats ; si oui avec quoi les fais-tu et comment
merci de me repondre c'est pour mon mémoire je galère malade