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 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177
|
import com.mysql.jdbc.Connection;
import com.mysql.jdbc.Statement;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
/*
* authentification.java
*
* Created on 28 janv. 2010, 14:18:16
*/
import java.sql.*;
/**
*
* @author 2MBA
*/
public class authentification extends javax.swing.JFrame {
/** Creates new form authentification */
public authentification() {
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.
*/
@SuppressWarnings("unchecked")
// <editor-fold defaultstate="collapsed" desc="Generated Code">
private void initComponents() {
jLabel1 = new javax.swing.JLabel();
jLabel2 = new javax.swing.JLabel();
jLabel3 = new javax.swing.JLabel();
textlogin = new javax.swing.JTextField();
textmdp = new javax.swing.JTextField();
btnseconnecter = new javax.swing.JButton();
setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
jLabel1.setText("authentification");
jLabel2.setText("login");
jLabel3.setText("mot de passe");
textlogin.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
textloginActionPerformed(evt);
}
});
textmdp.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
textmdpActionPerformed(evt);
}
});
btnseconnecter.setText("se connecter");
btnseconnecter.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
btnseconnecterActionPerformed(evt);
}
});
javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
getContentPane().setLayout(layout);
layout.setHorizontalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addGap(52, 52, 52)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
.addComponent(jLabel3)
.addComponent(jLabel2))
.addGap(74, 74, 74)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(textmdp, javax.swing.GroupLayout.PREFERRED_SIZE, 93, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(textlogin, javax.swing.GroupLayout.PREFERRED_SIZE, 93, javax.swing.GroupLayout.PREFERRED_SIZE)))
.addGroup(layout.createSequentialGroup()
.addGap(154, 154, 154)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(btnseconnecter)
.addComponent(jLabel1))))
.addContainerGap(117, Short.MAX_VALUE))
);
layout.setVerticalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addGap(22, 22, 22)
.addComponent(jLabel1)
.addGap(37, 37, 37)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(jLabel2)
.addComponent(textlogin, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
.addGap(60, 60, 60)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(jLabel3)
.addComponent(textmdp, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
.addGap(52, 52, 52)
.addComponent(btnseconnecter)
.addContainerGap(52, Short.MAX_VALUE))
);
pack();
}// </editor-fold>
private void textloginActionPerformed(java.awt.event.ActionEvent evt) {
}
private void textmdpActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
}
private void btnseconnecterActionPerformed(java.awt.event.ActionEvent evt) {
//Param de connection a la base de donné
String url = "jdbc:mysql://localhost:3306/parking"; // ex : postgresql://localhost/postgres
String log = "root";
String pass= "";
String login = "textlogin.getText()";
String motdepasse = "textmdp.getText()";
try
{
// connection
Connection connection = (Connection) DriverManager.getConnection(url,log,pass);
//interaction avec la base
Statement st = (Statement) connection.createStatement();
//Traitement
String sql = "SELECT * FROM gestionnaire g WHERE ((g.login == login ) AND (g.mdp == motdepasse)) ";
ResultSet resultat = st.executeQuery(sql);
if (resultat == null)
{ System.out.println ("erreur");}
else
{ System.out.println ("correct");}
//traitement
st.close();
connection.close();
}
catch(SQLException sqle)
{
sqle.printStackTrace();
}
}
/**
* @param args the command line arguments
*/
public static void main(String args[]) {
java.awt.EventQueue.invokeLater(new Runnable() {
public void run() {
new authentification().setVisible(true);
}
});
}
// Variables declaration - do not modify
private javax.swing.JButton btnseconnecter;
private javax.swing.JLabel jLabel1;
private javax.swing.JLabel jLabel2;
private javax.swing.JLabel jLabel3;
private javax.swing.JTextField textlogin;
private javax.swing.JTextField textmdp;
// End of variables declaration
} |
Partager