Advertisement
Guest User

Untitled

a guest
Apr 15th, 2016
83
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 8.09 KB | None | 0 0
  1. /*
  2. * To change this license header, choose License Headers in Project Properties.
  3. * To change this template file, choose Tools | Templates
  4. * and open the template in the editor.
  5. */
  6. package tp12;
  7.  
  8. import java.beans.Statement;
  9. import java.io.BufferedReader;
  10. import java.io.FileReader;
  11. import java.io.IOException;
  12. import java.sql.Connection;
  13. import java.sql.DriverManager;
  14. import java.sql.SQLException;
  15. import java.util.HashSet;
  16. import java.util.logging.Level;
  17. import java.util.logging.Logger;
  18.  
  19. /**
  20. *
  21. * @author sio
  22. */
  23. public class Restaurant_YUCAN2 extends javax.swing.JFrame {
  24.  
  25. Connection con;
  26. Statement req;
  27.  
  28. public Restaurant_YUCAN2() {
  29. initComponents();
  30. }
  31.  
  32. /**
  33. * This method is called from within the constructor to initialize the form.
  34. * WARNING: Do NOT modify this code. The content of this method is always
  35. * regenerated by the Form Editor.
  36. */
  37. @SuppressWarnings("unchecked")
  38. // <editor-fold defaultstate="collapsed" desc="Generated Code">
  39. private void initComponents() {
  40.  
  41. jLabel1 = new javax.swing.JLabel();
  42. jLabel2 = new javax.swing.JLabel();
  43. jLabel3 = new javax.swing.JLabel();
  44. jLabel4 = new javax.swing.JLabel();
  45. jLabel5 = new javax.swing.JLabel();
  46. jLabel6 = new javax.swing.JLabel();
  47. jLabel7 = new javax.swing.JLabel();
  48.  
  49. setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
  50. addWindowListener(new java.awt.event.WindowAdapter() {
  51. public void windowOpened(java.awt.event.WindowEvent evt) {
  52. formWindowOpened(evt);
  53. }
  54. });
  55.  
  56. jLabel1.setText("Nom:");
  57.  
  58. jLabel2.setText("Prenom:");
  59.  
  60. jLabel3.setText("Adresse 1:");
  61.  
  62. jLabel4.setText("Adresse 2:");
  63.  
  64. jLabel5.setText("Code postal");
  65.  
  66. jLabel6.setText("Ville:");
  67.  
  68. jLabel7.setText("Note:");
  69.  
  70. javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
  71. getContentPane().setLayout(layout);
  72. layout.setHorizontalGroup(
  73. layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
  74. .addGroup(layout.createSequentialGroup()
  75. .addGap(53, 53, 53)
  76. .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
  77. .addGroup(layout.createSequentialGroup()
  78. .addComponent(jLabel3)
  79. .addGap(0, 0, Short.MAX_VALUE))
  80. .addGroup(layout.createSequentialGroup()
  81. .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
  82. .addComponent(jLabel2)
  83. .addComponent(jLabel1)
  84. .addComponent(jLabel7)
  85. .addComponent(jLabel5)
  86. .addComponent(jLabel4)
  87. .addComponent(jLabel6))
  88. .addContainerGap(378, Short.MAX_VALUE))))
  89. );
  90. layout.setVerticalGroup(
  91. layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
  92. .addGroup(layout.createSequentialGroup()
  93. .addGap(29, 29, 29)
  94. .addComponent(jLabel1)
  95. .addGap(18, 18, 18)
  96. .addComponent(jLabel2)
  97. .addGap(18, 18, 18)
  98. .addComponent(jLabel3)
  99. .addGap(18, 18, 18)
  100. .addComponent(jLabel4)
  101. .addGap(18, 18, 18)
  102. .addComponent(jLabel5)
  103. .addGap(18, 18, 18)
  104. .addComponent(jLabel6)
  105. .addGap(18, 18, 18)
  106. .addComponent(jLabel7)
  107. .addContainerGap(51, Short.MAX_VALUE))
  108. );
  109.  
  110. pack();
  111. }// </editor-fold>
  112.  
  113. private void formWindowOpened(java.awt.event.WindowEvent evt) {
  114. try {
  115. //Chargement du pilote
  116. try {
  117. Class.forName("org.postgresql.Driver");
  118. } catch (ClassNotFoundException e) {
  119. System.out.println("Pilote mal installé ...");
  120. return;
  121. }
  122.  
  123. try {
  124. //Connexion
  125. con = DriverManager.getConnection("jdbc:postgresql://sophie/dbaptista_restaurant",
  126. "dbaptista", "linux");
  127. } catch (SQLException ex) {
  128. Logger.getLogger(Restaurant_YUCAN2.class.getName()).log(Level.SEVERE, null, ex);
  129. }
  130.  
  131. HashSet<Client> lesClients;
  132. lesClients = new HashSet<Client>();
  133. try {
  134. FileReader fclient = new FileReader("test.txt");
  135. BufferedReader liv = new BufferedReader(fclient);
  136. String ligne;
  137. ligne = liv.readLine();
  138. while (ligne != null) {
  139. String[] coupe = ligne.split(",");
  140. String nom = coupe[0];
  141. String prenom = coupe[1];
  142. String adr1 = coupe[2];
  143. String adr2 = coupe[3];
  144. String cp = coupe[4];
  145. String ville = coupe[5];
  146. String note = coupe[6];
  147. Client unClient = new Client(nom, prenom, adr1, adr2, cp, ville, note);
  148. lesClients.add(unClient);
  149. ligne = liv.readLine();
  150.  
  151. }
  152. } catch (IOException ex) {
  153. Logger.getLogger(Restaurant_YUCAN2.class.getName()).log(Level.SEVERE, null, ex);
  154. }
  155.  
  156. //Requête
  157. req = (Statement) con.createStatement();
  158. } catch (SQLException ex) {
  159. Logger.getLogger(Restaurant_YUCAN2.class.getName()).log(Level.SEVERE, null, ex);
  160. }
  161. }
  162.  
  163. /**
  164. * @param args the command line arguments
  165. */
  166. public static void main(String args[]) {
  167. /* Set the Nimbus look and feel */
  168. //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
  169. /* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
  170. * For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html
  171. */
  172. try {
  173. for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
  174. if ("Nimbus".equals(info.getName())) {
  175. javax.swing.UIManager.setLookAndFeel(info.getClassName());
  176. break;
  177. }
  178. }
  179. } catch (ClassNotFoundException ex) {
  180. java.util.logging.Logger.getLogger(Restaurant_YUCAN2.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
  181. } catch (InstantiationException ex) {
  182. java.util.logging.Logger.getLogger(Restaurant_YUCAN2.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
  183. } catch (IllegalAccessException ex) {
  184. java.util.logging.Logger.getLogger(Restaurant_YUCAN2.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
  185. } catch (javax.swing.UnsupportedLookAndFeelException ex) {
  186. java.util.logging.Logger.getLogger(Restaurant_YUCAN2.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
  187. }
  188. //</editor-fold>
  189.  
  190. /* Create and display the form */
  191. java.awt.EventQueue.invokeLater(new Runnable() {
  192. public void run() {
  193. new Restaurant_YUCAN2().setVisible(true);
  194. }
  195. });
  196. }
  197.  
  198. // Variables declaration - do not modify
  199. private javax.swing.JLabel jLabel1;
  200. private javax.swing.JLabel jLabel2;
  201. private javax.swing.JLabel jLabel3;
  202. private javax.swing.JLabel jLabel4;
  203. private javax.swing.JLabel jLabel5;
  204. private javax.swing.JLabel jLabel6;
  205. private javax.swing.JLabel jLabel7;
  206. // End of variables declaration
  207. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement