SHARE
TWEET

Untitled

a guest Aug 18th, 2018 73 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1.     public static Connection connectDB() {
  2.         Connection con = null;
  3.         final String LOCATION = "localhost";
  4.         final String PORT = "3306";
  5.         final String dbNAME = "EsmoreitChristens";
  6.         String usr = "root";
  7.         String pass = "";
  8.        
  9.         try {
  10.             Class.forName("com.mysql.jdbc.Driver");
  11.         } catch (ClassNotFoundException e) {
  12.             e.printStackTrace();
  13.         }
  14.  
  15.         try {
  16.             con = DriverManager.getConnection("jdbc:mysql://" + LOCATION + ":" + PORT
  17.             + "/" + dbNAME, usr, pass);
  18.             System.out.println("Connection established");
  19.         } catch (SQLException sqlExc) {
  20.             System.out.println("Connection error");
  21.             System.err.println(sqlExc);
  22.         }
  23.         return con;
  24.     }
  25.  
  26.     public static String[] getConfiguraties() {
  27.         Connection con = connectDB();
  28.         ArrayList configuratieNamenStack = new ArrayList();
  29.         String[] configuratieNamen = {""};
  30.         try {
  31.             Statement stmt = con.createStatement();
  32.             String count = "SELECT COUNT(*) FROM configuraties WHERE `iLocation` = 0 AND `jLocation` = 0";
  33.             String namen = "SELECT naam FROM configuraties WHERE `iLocation` = 0 AND `jLocation` = 0";
  34.             int amount = 0;
  35.             ResultSet a;
  36.             // GET AMOUNT
  37.             a = stmt.executeQuery(count);
  38.             while (a.next()){
  39.                 amount = a.getInt(1);
  40.                 configuratieNamen = new String[amount];
  41.             }
  42.             // GET STRING[]
  43.             a = stmt.executeQuery(namen);
  44.             while(a.next()) {
  45.                 configuratieNamenStack.add(a.getString("naam"));
  46.             }
  47.  
  48.         } catch (Exception excMySQL) {
  49.             System.out.print(excMySQL);
  50.         }
  51.         if (configuratieNamenStack.size() > 0) {
  52.             configuratieNamen = new String[configuratieNamenStack.size()];
  53.             configuratieNamenStack.toArray(configuratieNamen);
  54.         }
  55.         return configuratieNamen;
  56.     }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top