Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package be.howest.ti.forms.data;
- import be.howest.ti.forms.utils.FormsException;
- import java.sql.Connection;
- import java.sql.DriverManager;
- import java.sql.PreparedStatement;
- import java.sql.SQLException;
- import java.util.ArrayList;
- import java.util.List;
- import java.util.logging.Level;
- import java.util.logging.Logger;
- public class FormDA {
- public static final FormDA db = new FormDA();
- private Connection connection;
- private static final String URL = "jdbc:mysql://127.0.0.1:3306/forms?useSSL=false";
- private static final String USER = "root";
- private static final String PWD = "root";
- private FormDA(){
- try {
- Class.forName("com.mysql.jdbc.Driver");
- this.connection = DriverManager.getConnection(URL,USER,PWD);
- } catch (SQLException ex) {
- throw new RuntimeException("Unable to connect to DB.", ex);
- } catch (ClassNotFoundException ex) {
- throw new RuntimeException("Unable to load database driver.", ex);
- }
- }
- public List<String> getFormNames(){
- List<String> result = new ArrayList<>();
- try {
- PreparedStatement stmt = connection.prepareStatement(SqlStatements.SELECT_FORM_NAMES);
- } catch (SQLException ex) {
- throw new FormsException("Failed to retrieve form names.", ex);
- }
- return result;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement