Advertisement
Guest User

Untitled

a guest
Dec 16th, 2016
84
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.25 KB | None | 0 0
  1. package select_test;
  2.  
  3. /*
  4. user: spider_user
  5. config spider: EQ46FP7CW0gz3Rlu
  6. database: spider_db
  7. */
  8.  
  9.  
  10. import java.sql.*;
  11. public class database {
  12.     private String user="spider_user";
  13.     private String host="localhost";
  14.     private String password="EQ46FP7CW0gz3Rlu";
  15.     private String db="spider_db";
  16.     private Connection connection = null;
  17.     Statement st = null;
  18.     public database(){
  19.         this.connect();
  20.         try {
  21.             this.st=dbFlow().createStatement();
  22.         } catch (SQLException e) {
  23.             // TODO Auto-generated catch block
  24.             e.printStackTrace();
  25.         }
  26.     }
  27.     public void connect(){
  28.         String url = "jdbc:mysql://localhost:3306/"+this.db;
  29.         String user = this.user;
  30.         String password = this.password;
  31.         try {
  32.             this.connection = DriverManager.getConnection(url, user, password);
  33.         } catch (SQLException e) {
  34.             e.printStackTrace();
  35.         } catch (Exception e) {
  36.             System.out.println(e.getMessage());
  37.         }
  38.     }
  39.     public void query(String query) throws SQLException{
  40.         st.executeUpdate(query);
  41.     }
  42.     private Connection dbFlow(){
  43.         return this.connection;
  44.     }
  45.     public void disconnect(){
  46.         try {
  47.             dbFlow().close();
  48.         } catch (SQLException e) {
  49.             // TODO Auto-generated catch block
  50.             e.printStackTrace();
  51.         }
  52.     }
  53. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement