SHARE
TWEET

Untitled

a guest Jun 8th, 2017 57 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. package uk.co.grahamhowden;
  2.  
  3. import java.sql.Connection;
  4. import java.sql.DriverManager;
  5. import java.sql.ResultSet;
  6. import java.sql.SQLException;
  7. import java.sql.Statement;
  8.  
  9. public class DatabaseClass {
  10.  
  11.     private DatabaseClass(){
  12.        
  13.     }
  14.    
  15.     public static ResultSet databaseQuery( String sqlStatement ) throws SQLException{
  16.        
  17.         Connection con = DriverManager.getConnection("jdbc:mysql:///forum",
  18.                 "root", "secret");
  19.         Statement st = con.createStatement();
  20.         ResultSet rs = st.executeQuery(sqlStatement);
  21.         if(con != null){
  22.             con.close();
  23.         }
  24.         if(st != null){
  25.             st.close();
  26.         }
  27.         return rs;
  28.        
  29.     }
  30.    
  31.     public void databaseUpdate( String sqlStatement ) throws SQLException{
  32.         Connection con = DriverManager.getConnection("jdbc:mysql:///forum",
  33.                 "root", "secret");
  34.         Statement st = con.createStatement();
  35.         st.executeUpdate(sqlStatement);
  36.         if(con != null){
  37.             con.close();
  38.         }
  39.         if(st != null){
  40.             st.close();
  41.         }
  42.     }
  43.    
  44. }
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