Advertisement
Guest User

Untitled

a guest
Jan 16th, 2018
107
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.40 KB | None | 0 0
  1. package be.howest.ti.forms.data;
  2.  
  3. import be.howest.ti.forms.utils.FormsException;
  4. import java.sql.Connection;
  5. import java.sql.DriverManager;
  6. import java.sql.PreparedStatement;
  7. import java.sql.SQLException;
  8. import java.util.ArrayList;
  9. import java.util.List;
  10. import java.util.logging.Level;
  11. import java.util.logging.Logger;
  12.  
  13. public class FormDA {
  14. public static final FormDA db = new FormDA();
  15.  
  16. private Connection connection;
  17.  
  18. private static final String URL = "jdbc:mysql://127.0.0.1:3306/forms?useSSL=false";
  19. private static final String USER = "root";
  20. private static final String PWD = "root";
  21.  
  22. private FormDA(){
  23. try {
  24. Class.forName("com.mysql.jdbc.Driver");
  25. this.connection = DriverManager.getConnection(URL,USER,PWD);
  26. } catch (SQLException ex) {
  27. throw new RuntimeException("Unable to connect to DB.", ex);
  28. } catch (ClassNotFoundException ex) {
  29. throw new RuntimeException("Unable to load database driver.", ex);
  30. }
  31. }
  32.  
  33. public List<String> getFormNames(){
  34. List<String> result = new ArrayList<>();
  35. try {
  36. PreparedStatement stmt = connection.prepareStatement(SqlStatements.SELECT_FORM_NAMES);
  37. } catch (SQLException ex) {
  38. throw new FormsException("Failed to retrieve form names.", ex);
  39. }
  40. return result;
  41. }
  42. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement