Advertisement
Guest User

Untitled

a guest
Jun 10th, 2017
65
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.96 KB | None | 0 0
  1. package org.server.util.database;
  2.  
  3. import java.sql.Connection;
  4. import java.sql.DriverManager;
  5. import java.sql.Statement;
  6. import java.sql.ResultSet;
  7.  
  8. /**
  9.  * Handles database actions
  10.  * @author DHAReauxK
  11.  */
  12.  
  13. public class Integration {
  14.  
  15.     /**
  16.      * @note temporary strings
  17.      */
  18.     private String host, database, username, password = "";
  19.  
  20.     public void connect() throws Exception {
  21.         Class.forName("com.mysql.jdbc.Driver").newInstance ();
  22.         connection = DriverManager.getConnection("jdbc:mysql://" + host + "/" + database + "", username, password);
  23.         statement = connection.createStatement();
  24.     }
  25.  
  26.     public ResultSet query(String s) {
  27.         try {
  28.             if (s.toLowerCase().startsWith("select")) {
  29.                 ResultSet rs = statement.executeQuery(s);
  30.                 return rs;
  31.             } else {
  32.                 statement.executeUpdate(s);
  33.             }
  34.             return null;
  35.         } catch (Exception e) {
  36.             e.printStackTrace();
  37.         }
  38.         return null;
  39.     }
  40.  
  41.     private Connection connection;
  42.     private Statement statement;
  43. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement