Guest User

Untitled

a guest
Oct 11th, 2018
105
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.26 KB | None | 0 0
  1. package com.grenames.services.ircrelay;
  2.  
  3. import java.sql.DriverManager;
  4. import java.sql.ResultSet;
  5. import java.sql.SQLException;
  6. import java.util.HashMap;
  7. import java.util.Map;
  8.  
  9. import com.mysql.jdbc.Connection;
  10. import com.mysql.jdbc.Statement;
  11.  
  12. public class Config {
  13.    
  14.     Map<String,String> config = new HashMap<String, String>();
  15.     Connection configConnection = null;
  16.  
  17.    
  18.     public String get(String name){
  19.         Statement st = null;
  20.         ResultSet rs = null;
  21.         try {
  22.             st = (Statement) configConnection.createStatement();
  23.         } catch (SQLException e) {
  24.             e.printStackTrace();
  25.         }
  26.         try {
  27.             rs = st.executeQuery("SELECT value FROM config where name='"+name+"'");
  28.         } catch (SQLException e) {
  29.             e.printStackTrace();
  30.         }
  31.         try {
  32.             if(rs.getFetchSize() != 0){
  33.                 try {
  34.                     rs.next();
  35.                     return rs.getString(1);
  36.                 } catch (SQLException e) {
  37.                     e.printStackTrace();
  38.                 }
  39.             }
  40.         } catch (SQLException e) {
  41.             e.printStackTrace();
  42.         }
  43.         return null;
  44.     }
  45.    
  46.     public boolean set(String name, String value){
  47.         return false;
  48.     }
  49.    
  50.     public Config(){
  51.         try {
  52.             configConnection = (Connection) DriverManager.getConnection("jdbc:mysql://localhost:3306/GrenamesBot","root","toor");
  53.         } catch (SQLException e) {
  54.             e.printStackTrace();
  55.         }
  56.     }
  57. }
Add Comment
Please, Sign In to add comment