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 178 179 180 181
|
/*
* Connection.java
*
* Created on 11 mars 2008, 15:45
*/
package Test;
import java.sql.*;
import java.lang.*;
/**
*
* @author adminlocal
*/
public class Autorisation extends javax.swing.JFrame {
String NumCodeBarre;
String NumBadge = "3";
/** Creates new form Connection */
public Autorisation() {
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.
*/
// <editor-fold defaultstate="collapsed" desc="Generated Code">
private void initComponents() {
jTextFieldAutorisation = new javax.swing.JTextField();
jButtonBadge = new javax.swing.JButton();
jTextFieldNumBadge = new javax.swing.JTextField();
setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
jTextFieldAutorisation.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jTextFieldAutorisationActionPerformed(evt);
}
});
jButtonBadge.setText("Passage du badge");
jButtonBadge.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jButtonBadgeActionPerformed(evt);
}
});
jTextFieldNumBadge.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jTextFieldNumBadgeActionPerformed(evt);
}
});
org.jdesktop.layout.GroupLayout layout = new org.jdesktop.layout.GroupLayout(getContentPane());
getContentPane().setLayout(layout);
layout.setHorizontalGroup(
layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
.add(layout.createSequentialGroup()
.addContainerGap(108, Short.MAX_VALUE)
.add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
.add(org.jdesktop.layout.GroupLayout.TRAILING, layout.createSequentialGroup()
.add(jTextFieldAutorisation, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 186, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
.add(106, 106, 106))
.add(org.jdesktop.layout.GroupLayout.TRAILING, layout.createSequentialGroup()
.add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.TRAILING, false)
.add(org.jdesktop.layout.GroupLayout.LEADING, jTextFieldNumBadge)
.add(org.jdesktop.layout.GroupLayout.LEADING, jButtonBadge, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
.add(136, 136, 136))))
);
layout.setVerticalGroup(
layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
.add(layout.createSequentialGroup()
.add(68, 68, 68)
.add(jTextFieldNumBadge, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
.add(60, 60, 60)
.add(jButtonBadge)
.add(48, 48, 48)
.add(jTextFieldAutorisation, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
.addContainerGap(62, Short.MAX_VALUE))
);
pack();
}// </editor-fold>
private void jTextFieldAutorisationActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
}
private void jButtonBadgeActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
Connection();
}
/**
* @param args the command line arguments
*/
public void Connection(){
Connection conn;
Statement stmt;
ResultSet rs;
String pilote = "org.gjt.mm.mysql.Driver";
String url = new String("jdbc:mysql://10.104.100.57:3306/snecma");
try
{
Class.forName(pilote);
conn = DriverManager.getConnection(url,"root","root");
stmt = conn.createStatement();
rs = stmt.executeQuery("SELECT * From utilisateur");
while (rs.next())
{
System.out.println(rs.getString(1)+ " " + rs.getString(2) + " " + rs.getString(3)+ " " + rs.getString(4) + "\n ");
}
if(NumBadge.equals(NumCodeBarre))
AccesAutorise();
else
AccesRefuse();
rs.close();
stmt.close();
conn.close();
}
catch ( SQLException E)
{
System.out.println("SQLException: " + E.getMessage());
System.out.println("SQLState: " + E.getSQLState());
System.out.println("VendorError: " + E.getErrorCode());
}
catch ( ClassNotFoundException E)
{
E.printStackTrace();
}
}
public void AccesAutorise() {
jTextFieldAutorisation.setText("L'accès est autorisé");
}
public void AccesRefuse() {
jTextFieldAutorisation.setText("L'accès est refusé");
}
public static void main(String args[]) {
java.awt.EventQueue.invokeLater(new Runnable() {
public void run() {
new Autorisation().setVisible(true);
}
});
}
// Variables declaration - do not modify
private javax.swing.JButton jButtonBadge;
private javax.swing.JTextField jTextFieldAutorisation;
private javax.swing.JTextField jTextFieldNumBadge;
// End of variables declaration
} |
Partager