bonsoir
je suis debutante en java .j'essaie d'etablir une connexion entre oracle et net beans mais en vain .s'il vous plait m'aider le code ceci
package appmedic;
import java .sql.*;
import javax.swing.JOptionPane;
import java .util.logging.Level;
import java.util.logging.Logger;
/**
*
* @author l'expert
*/
public class identification extends javax.swing.JFrame {
/** Creates new form identification */
public identification() {
initComponents();
}
public class ConnectionBD{
private Connection con;
private Statement instruction;
protected ResultSet resultat;
String l_url="jdbc:oracle:thin:@localhost:1521:orcl";
String l_uid="system";
String l_pwd="ch05940563";
String l_driver="oracle.jdbc.OracleDriver";
public ConnectionBD(){
try
{
Class.forName("oracle.jdbc.OracleDriver");
con=DriverManager.getConnection(l_url, l_uid, l_pwd);
instruction=con.createStatement();
}
catch (ClassNotFoundException ex)
{
System.err.println("Problème de pilote");
}
catch(SQLException ex)
{System.err.println("Base de données non trouve ou requete incorrect");
}
}}
/** 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.
*/
@SuppressWarnings("unchecked")
// <editor-fold defaultstate="collapsed" desc="Generated Code">
private void initComponents() {
jTextField2 = new javax.swing.JTextField();
jPanel2 = new javax.swing.JPanel();
jPanel1 = new javax.swing.JPanel();
jLabel1 = new javax.swing.JLabel();
jLabel2 = new javax.swing.JLabel();
jLabel3 = new javax.swing.JLabel();
loge = new javax.swing.JTextField();
jButton1 = new javax.swing.JButton();
mot = new javax.swing.JPasswordField();
annuler = new javax.swing.JButton();
jButton2 = new javax.swing.JButton();
jLabel4 = new javax.swing.JLabel();
jTextField2.setText("jTextField2");
setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
setTitle("Authentification");
setMinimumSize(new java.awt.Dimension(535, 377));
getContentPane().setLayout(null);
jPanel2.setBackground(new java.awt.Color(204, 204, 204));
jPanel1.setBackground(new java.awt.Color(204, 204, 204));
jPanel1.setBorder(javax.swing.BorderFactory.createEtchedBorder());
jLabel1.setIcon(new javax.swing.ImageIcon("C:\\Documents and Settings\\l'expert\\Mes documents\\bienve\\keyword\\images.jpg")); // NOI18N
jLabel1.setText("jLabel1");
jLabel1.setToolTipText("");
jLabel2.setFont(new java.awt.Font("Tahoma", 3, 18));
jLabel2.setText("login");
jLabel3.setFont(new java.awt.Font("Tahoma", 3, 18));
jLabel3.setText("mot de passe");
loge.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
logeActionPerformed(evt);
}
});
jButton1.setFont(new java.awt.Font("Tahoma", 3, 18));
jButton1.setText("Valider");
jButton1.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jButton1ActionPerformed(evt);
}
});
mot.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
motActionPerformed(evt);
}
});
annuler.setFont(new java.awt.Font("Tahoma", 1, 18));
annuler.setText("Annuler");
annuler.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
annulerActionPerformed(evt);
}
});
jButton2.setText("ok");
jButton2.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jButton2ActionPerformed(evt);
}
});
javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
jPanel1.setLayout(jPanel1Layout);
jPanel1Layout.setHorizontalGroup(
jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(jPanel1Layout.createSequentialGroup()
.addGap(10, 10, 10)
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(jPanel1Layout.createSequentialGroup()
.addComponent(jLabel1, javax.swing.GroupLayout.PREFERRED_SIZE, 121, javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(jLabel3)
.addComponent(jLabel2)))
.addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel1Layout.createSequentialGroup()
.addComponent(jButton2)
.addGap(18, 18, 18)
.addComponent(jButton1)
.addGap(12, 12, 12)))
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(jPanel1Layout.createSequentialGroup()
.addGap(33, 33, 33)
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(mot, javax.swing.GroupLayout.DEFAULT_SIZE, 113, Short.MAX_VALUE)
.addComponent(loge, javax.swing.GroupLayout.DEFAULT_SIZE, 113, Short.MAX_VALUE))
.addGap(38, 38, 38))
.addGroup(jPanel1Layout.createSequentialGroup()
.addGap(18, 18, 18)
.addComponent(annuler)
.addContainerGap())))
);
jPanel1Layout.setVerticalGroup(
jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(jPanel1Layout.createSequentialGroup()
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(jPanel1Layout.createSequentialGroup()
.addGap(79, 79, 79)
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(jLabel2)
.addComponent(loge, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
.addGap(28, 28, 28)
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(jLabel3)
.addComponent(mot, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
.addGap(18, 18, 18)
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(jButton1)
.addComponent(jButton2))
.addComponent(annuler)))
.addGroup(jPanel1Layout.createSequentialGroup()
.addGap(49, 49, 49)
.addComponent(jLabel1)))
.addContainerGap(25, Short.MAX_VALUE))
);
jLabel4.setFont(new java.awt.Font("Tahoma", 3, 18));
jLabel4.setForeground(new java.awt.Color(204, 102, 255));
jLabel4.setIcon(new javax.swing.ImageIcon("C:\\Documents and Settings\\l'expert\\Mes documents\\Mes images\\Groupe_chimique_tunisien.jpg")); // NOI18N
jLabel4.setText("Groupe chimique tunisien");
javax.swing.GroupLayout jPanel2Layout = new javax.swing.GroupLayout(jPanel2);
jPanel2.setLayout(jPanel2Layout);
jPanel2Layout.setHorizontalGroup(
jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(jPanel2Layout.createSequentialGroup()
.addGap(37, 37, 37)
.addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(jLabel4, javax.swing.GroupLayout.PREFERRED_SIZE, 473, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
.addContainerGap(20, Short.MAX_VALUE))
);
jPanel2Layout.setVerticalGroup(
jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel2Layout.createSequentialGroup()
.addContainerGap()
.addComponent(jLabel4, javax.swing.GroupLayout.PREFERRED_SIZE, 80, Short.MAX_VALUE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addGap(41, 41, 41))
);
getContentPane().add(jPanel2);
jPanel2.setBounds(0, -10, 530, 360);
getAccessibleContext().setAccessibleName("authentification");
pack();
}// </editor-fold>
private void logeActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
}
private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {
String l= loge.getText();
char[] k=mot.getPassword();
String c="administrateur";
String d="infirmier";
String g= "1234";
String b= "4567";
String f=String.valueOf(k);
if (l.equals(c)& f.equals(g)){
this .dispose();
new Administration().setVisible(true);
}else
if (l.equals(d)&f.equals(b)){
this.dispose();
new acceuil().setVisible(true);
}else
if ((loge.getText().equals(""))& (mot .getText().equals("")))
{
JOptionPane.showMessageDialog(this, "les champs sont déja vide!!", "verification de champ ",JOptionPane.INFORMATION_MESSAGE);
} else
{JOptionPane.showMessageDialog(this, "FAIS Attention votre login ou mot de passe est erroné", "authentification", JOptionPane.INFORMATION_MESSAGE);
}
// TODO add your handling code here:
}
private void annulerActionPerformed(java.awt.event.ActionEvent evt) {
if ((loge.getText().equals("")& (mot.getText().equals("")
))){JOptionPane.showMessageDialog(this, "les champs sont déja vide!!", "verification de champ ",JOptionPane.INFORMATION_MESSAGE);
} else{
loge.setText("");
mot.setText("");
// TODO add your handling code here:
}
}
private void motActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
}
private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {
if((loge.getText().equals("+login+")&(mot.getText().equals("+passe")))){
this.dispose();
new acceuil().setVisible(true);}
// 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 identification().setVisible(true);
}
});
}
// Variables declaration - do not modify
private javax.swing.JButton annuler;
private javax.swing.JButton jButton1;
private javax.swing.JButton jButton2;
private javax.swing.JLabel jLabel1;
private javax.swing.JLabel jLabel2;
private javax.swing.JLabel jLabel3;
private javax.swing.JLabel jLabel4;
private javax.swing.JPanel jPanel1;
private javax.swing.JPanel jPanel2;
private javax.swing.JTextField jTextField2;
private javax.swing.JTextField loge;
private javax.swing.JPasswordField mot;
// End of variables declaration
}
les bouton annuler et valider se fonctionne car il ne connecte pas au base maisle bouton ok ne fonctionne pas.
merci