Probléme jdbc
futur ingenieure
Messages postés
185
Statut
Membre
-
futur ingenieure Messages postés 185 Statut Membre -
futur ingenieure Messages postés 185 Statut Membre -
Bonjour,
je travaille avec eclipse , et je je suis entrai de faire une connexion à une BD
Pouvez vous m'aidez à corriger cette erreur SVP?
GRAVE: null
java.sql.SQLException: [Microsoft][Gestionnaire de pilotes ODBC] Source de données introuvable et nom de pilote non spécifié
merci d'avance
je travaille avec eclipse , et je je suis entrai de faire une connexion à une BD
Pouvez vous m'aidez à corriger cette erreur SVP?
GRAVE: null
java.sql.SQLException: [Microsoft][Gestionnaire de pilotes ODBC] Source de données introuvable et nom de pilote non spécifié
merci d'avance
A voir également:
- Probléme jdbc
- [JDBC] Requête préparée avec des champs nommés. pas de ? - Forum Java
3 réponses
Bonjour,
Si tu mettais ton code, ça serait plus facile d'essayer de te corriger. Ma boule de cristal et moi sommes en froid en ce moment.
;o)
Si tu mettais ton code, ça serait plus facile d'essayer de te corriger. Ma boule de cristal et moi sommes en froid en ce moment.
;o)
public class ClientInterface extends javax.swing.JFrame {
/**
*
*/
private static final long serialVersionUID = 1L;
/** Creates new form ClientInterface */
public ClientInterface() {
initComponents();
}
/** This method is called from within the constructor to
* initialize the form.
* WARNING: Do NOT modify this code. The content of this method is
* always regenerated by the Form Editor.
*/
private void initComponents() {
jLabel1 = new javax.swing.JLabel();
jLabel2 = new javax.swing.JLabel();
jTextField1 = new javax.swing.JTextField();
jButton1 = new javax.swing.JButton();
jPasswordField1 = new javax.swing.JPasswordField();
setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
jLabel1.setText("Password");
jLabel2.setText("Login");
jButton1.setText("valider");
jButton1.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jButton1ActionPerformed(evt);
}
});
jPasswordField1.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jPasswordField1ActionPerformed(evt);
}
});
javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
getContentPane().setLayout(layout);
layout.setHorizontalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
.addGap(57, 57, 57)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
.addGroup(layout.createSequentialGroup()
.addComponent(jLabel1, javax.swing.GroupLayout.PREFERRED_SIZE, 133, javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED))
.addGroup(layout.createSequentialGroup()
.addComponent(jLabel2, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addGap(31, 31, 31)))
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(jButton1)
.addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
.addComponent(jPasswordField1, javax.swing.GroupLayout.Alignment.TRAILING)
.addComponent(jTextField1, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, 123, Short.MAX_VALUE))))
.addGap(140, 140, 140))
);
layout.setVerticalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addGap(118, 118, 118)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(jTextField1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(jLabel2, javax.swing.GroupLayout.PREFERRED_SIZE, 38, javax.swing.GroupLayout.PREFERRED_SIZE))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(jLabel1, javax.swing.GroupLayout.PREFERRED_SIZE, 37, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(jPasswordField1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
.addGap(29, 29, 29)
.addComponent(jButton1)
.addContainerGap(48, Short.MAX_VALUE))
);
pack();
}// </editor-fold>
private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {
try {
String log = jTextField1.getText();
String mp = jPasswordField1.getSelectedText();
//boolean test = false;
//System.out.println(mp);
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver").newInstance();
// Class.forName("com.microdoft.jdbc.sqlserver.SQLServerDriver").newInstance();
// Class.forName("com.mysql.jdbc.Driver").newInstance();
System.out.println("Chargement du pilote reussi !");
// String url ="jdbc:microsoft:sqlserver://localhost:3306/iptv;";//+"user='';password='',DatabaseName=iptv";
//String url = "jdbc:odbc://localhost:3306/iptv";
System.out.println("ssssssss");
Connection con = DriverManager.getConnection("jdbc:odbc:iptv","root","0000");
System.out.println("ssssssss0000");
Statement stmt = con.createStatement();
System.out.println("ssssssss11222211");
ResultSet rs = stmt.executeQuery("select * from clients where (login='" + log + "') and (password ='" + mp + "');");
System.out.println("ssssssss1111");
while(rs.next()){
//if (rs.equals(true)){
System.out.println(rs.getString(1) + "vous etes identifiés");
//int x=1;
}
//if (rs.getBoolean(1))
// test = true;
//-- rs.close();
//-- stmt.close();
con.close();
//return test;
} catch (SQLException ex) {
Logger.getLogger(ClientInterface.class.getName()).log(Level.SEVERE, null, ex);
} catch (InstantiationException ex) {
Logger.getLogger(ClientInterface.class.getName()).log(Level.SEVERE, null, ex);
} catch (IllegalAccessException ex) {
Logger.getLogger(ClientInterface.class.getName()).log(Level.SEVERE, null, ex);
} catch (ClassNotFoundException ex) {
Logger.getLogger(ClientInterface.class.getName()).log(Level.SEVERE, null, ex);
}
}
private void jPasswordField1ActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
}
/**
* @param args the command line arguments
*/
public static void main(String args[]) {
java.awt.EventQueue.invokeLater(new Runnable() {
public void run() {
new ClientInterface().setVisible(true);
}
});
}
// Variables declaration - do not modify
private javax.swing.JButton jButton1;
private javax.swing.JLabel jLabel1;
private javax.swing.JLabel jLabel2;
private javax.swing.JPasswordField jPasswordField1;
private javax.swing.JTextField jTextField1;
// End of variables declaration
}
/**
*
*/
private static final long serialVersionUID = 1L;
/** Creates new form ClientInterface */
public ClientInterface() {
initComponents();
}
/** This method is called from within the constructor to
* initialize the form.
* WARNING: Do NOT modify this code. The content of this method is
* always regenerated by the Form Editor.
*/
private void initComponents() {
jLabel1 = new javax.swing.JLabel();
jLabel2 = new javax.swing.JLabel();
jTextField1 = new javax.swing.JTextField();
jButton1 = new javax.swing.JButton();
jPasswordField1 = new javax.swing.JPasswordField();
setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
jLabel1.setText("Password");
jLabel2.setText("Login");
jButton1.setText("valider");
jButton1.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jButton1ActionPerformed(evt);
}
});
jPasswordField1.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jPasswordField1ActionPerformed(evt);
}
});
javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
getContentPane().setLayout(layout);
layout.setHorizontalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
.addGap(57, 57, 57)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
.addGroup(layout.createSequentialGroup()
.addComponent(jLabel1, javax.swing.GroupLayout.PREFERRED_SIZE, 133, javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED))
.addGroup(layout.createSequentialGroup()
.addComponent(jLabel2, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addGap(31, 31, 31)))
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(jButton1)
.addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
.addComponent(jPasswordField1, javax.swing.GroupLayout.Alignment.TRAILING)
.addComponent(jTextField1, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, 123, Short.MAX_VALUE))))
.addGap(140, 140, 140))
);
layout.setVerticalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addGap(118, 118, 118)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(jTextField1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(jLabel2, javax.swing.GroupLayout.PREFERRED_SIZE, 38, javax.swing.GroupLayout.PREFERRED_SIZE))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(jLabel1, javax.swing.GroupLayout.PREFERRED_SIZE, 37, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(jPasswordField1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
.addGap(29, 29, 29)
.addComponent(jButton1)
.addContainerGap(48, Short.MAX_VALUE))
);
pack();
}// </editor-fold>
private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {
try {
String log = jTextField1.getText();
String mp = jPasswordField1.getSelectedText();
//boolean test = false;
//System.out.println(mp);
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver").newInstance();
// Class.forName("com.microdoft.jdbc.sqlserver.SQLServerDriver").newInstance();
// Class.forName("com.mysql.jdbc.Driver").newInstance();
System.out.println("Chargement du pilote reussi !");
// String url ="jdbc:microsoft:sqlserver://localhost:3306/iptv;";//+"user='';password='',DatabaseName=iptv";
//String url = "jdbc:odbc://localhost:3306/iptv";
System.out.println("ssssssss");
Connection con = DriverManager.getConnection("jdbc:odbc:iptv","root","0000");
System.out.println("ssssssss0000");
Statement stmt = con.createStatement();
System.out.println("ssssssss11222211");
ResultSet rs = stmt.executeQuery("select * from clients where (login='" + log + "') and (password ='" + mp + "');");
System.out.println("ssssssss1111");
while(rs.next()){
//if (rs.equals(true)){
System.out.println(rs.getString(1) + "vous etes identifiés");
//int x=1;
}
//if (rs.getBoolean(1))
// test = true;
//-- rs.close();
//-- stmt.close();
con.close();
//return test;
} catch (SQLException ex) {
Logger.getLogger(ClientInterface.class.getName()).log(Level.SEVERE, null, ex);
} catch (InstantiationException ex) {
Logger.getLogger(ClientInterface.class.getName()).log(Level.SEVERE, null, ex);
} catch (IllegalAccessException ex) {
Logger.getLogger(ClientInterface.class.getName()).log(Level.SEVERE, null, ex);
} catch (ClassNotFoundException ex) {
Logger.getLogger(ClientInterface.class.getName()).log(Level.SEVERE, null, ex);
}
}
private void jPasswordField1ActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
}
/**
* @param args the command line arguments
*/
public static void main(String args[]) {
java.awt.EventQueue.invokeLater(new Runnable() {
public void run() {
new ClientInterface().setVisible(true);
}
});
}
// Variables declaration - do not modify
private javax.swing.JButton jButton1;
private javax.swing.JLabel jLabel1;
private javax.swing.JLabel jLabel2;
private javax.swing.JPasswordField jPasswordField1;
private javax.swing.JTextField jTextField1;
// End of variables declaration
}
C'est en vrac ton truc ...
Pourquoi ne pas faire une classe Connexion ?
A quelle base veux-tu te connecter ?
D'autre part, as-tu ajouté ton jar dans le classpath ?
Regarde ici, peut être une solution pour toi.
;o)
Pourquoi ne pas faire une classe Connexion ?
A quelle base veux-tu te connecter ?
D'autre part, as-tu ajouté ton jar dans le classpath ?
Regarde ici, peut être une solution pour toi.
;o)