Guest User

Untitled

a guest
Feb 3rd, 2018
80
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.37 KB | None | 0 0
  1. package com.transfile.dao;
  2.  
  3. import com.transfile.model.Configuration;
  4.  
  5. import java.sql.Connection;
  6. import java.sql.DriverManager;
  7. import java.sql.PreparedStatement;
  8. import java.sql.ResultSet;
  9. import java.sql.SQLException;
  10. import java.util.ArrayList;
  11. import java.util.List;
  12.  
  13. public class ConfigurationDao {
  14. private static final String DB_DRIVER = "com.mysql.cj.jdbc.Driver";
  15. private static final String DB_CONNECTION = "jdbc:mysql://localhost/test?autoReconnect=true&useSSL=false";
  16. private static final String DB_USER = "test";
  17. private static final String DB_PASSWORD = "test";
  18.  
  19. public List<Configuration> findAllConfigurations() throws SQLException {
  20. List<Configuration> result = new ArrayList<Configuration>();
  21.  
  22.  
  23. Connection dbConnection = null;
  24. PreparedStatement preparedStatement = null;
  25.  
  26. String selectSQL = "SELECT * FROM CONFIGURATION";
  27.  
  28. try
  29. {
  30. // Ouverture de la connection vers la BDD
  31. dbConnection = getDBConnection();
  32.  
  33. preparedStatement = dbConnection.prepareStatement(selectSQL);
  34.  
  35. // execute select SQL statement
  36. ResultSet rs = preparedStatement.executeQuery();
  37.  
  38. while (rs.next()) {
  39.  
  40. String configId = rs.getString("CONFIG_ID");
  41. String nameFile = rs.getString("NAME_FILE");
  42. String profile = rs.getString("PROFILE");
  43. String nameDest = rs.getString("NAME_DEST");
  44. String nameZip = rs.getString("NAME_ZIP");
  45. Boolean delete = rs.getBoolean("DELETE");
  46. Integer multiple = rs.getInt("MULTIPLE");
  47. Integer occurence = rs.getInt("OCCURENCE");
  48. String comment = rs.getString("COMMENT");
  49. String listServ = rs.getString("LIST_SERV");
  50. String release = rs.getString("RELEASE");
  51.  
  52. System.out.println("userid : " + configId);
  53. System.out.println("username : " + nameFile);
  54. System.out.println("profile : " + profile);
  55. System.out.println("nameDest : " + nameDest);
  56. System.out.println("nameZip : " + nameZip);
  57. System.out.println("delete : " + delete);
  58. System.out.println("multiple : " + multiple);
  59. System.out.println("occurence : " + occurence);
  60. System.out.println("comment : " + comment);
  61. System.out.println("listServ : " + listServ);
  62. System.out.println("release : " + release);
  63.  
  64. }
  65.  
  66. }catch(
  67. SQLException e)
  68. {
  69.  
  70. System.out.println(e.getMessage());
  71.  
  72. }finally
  73. {
  74.  
  75. if (preparedStatement != null) {
  76. preparedStatement.close();
  77. }
  78.  
  79. if (dbConnection != null) {
  80. dbConnection.close();
  81. }
  82.  
  83. }
  84.  
  85. return result;
  86. }
  87.  
  88. private static Connection getDBConnection() {
  89.  
  90. Connection dbConnection = null;
  91.  
  92. try {
  93.  
  94. Class.forName(DB_DRIVER);
  95. dbConnection = DriverManager.getConnection(
  96. DB_CONNECTION, DB_USER,DB_PASSWORD);
  97. return dbConnection;
  98.  
  99. } catch (SQLException e) {
  100.  
  101. System.out.println(e.getMessage());
  102.  
  103. } catch (ClassNotFoundException e) {
  104. e.printStackTrace();
  105. }
  106.  
  107. return dbConnection;
  108.  
  109. }
  110.  
  111. }
Add Comment
Please, Sign In to add comment