Mattie

Mattie

Jan 2nd, 2011
75
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.35 KB | None | 0 0
  1. package bot_versie_08;
  2.  
  3. import java.sql.*;
  4.  
  5. public class Database
  6. {
  7.  
  8.     private Statement   stmt;
  9.     private Connection  con;
  10.     private String      USERNAME    = "admin_ircbot";
  11.     private String      PASSWORD    = "password";
  12.     private String      DBNAME      = "admin_ircbot";
  13.     private String      DBURL       = "jdbc:mysql://mattie-systems.nl:3306/" + DBNAME;
  14.  
  15.     public Database()
  16.     {
  17.  
  18.         try
  19.         {
  20.  
  21.             // Register the JDBC driver for MySQL.
  22.             Class.forName("com.mysql.jdbc.Driver");
  23.  
  24.             // Define URL of database server for
  25.             // database named mysql on the localhost
  26.             // with the default port number 3306.
  27.             String url = DBURL;
  28.  
  29.             // Get a connection to the database for a
  30.             // user named root with a blank password.
  31.             // This user is the default administrator
  32.             // having full privileges to do anything.
  33.             con = DriverManager.getConnection(url, USERNAME, PASSWORD);
  34.  
  35.             // Display URL and connection information
  36.             System.out.println("URL: " + url);
  37.             System.out.println("Connection: " + con);
  38.  
  39.             // Get a Statement object
  40.             stmt = con.createStatement();
  41.  
  42.         } catch (Exception e)
  43.         {
  44.  
  45.             genereerCriticalError(e);
  46.         }
  47.     }
  48.  
  49.     public void genereerError(Exception e)// the program CAN continue
  50.     {
  51.         e.printStackTrace();
  52.     }
  53.  
  54.     public void genereerCriticalError(Exception e)// the program CAN NOT continue and quits
  55.     {
  56.         e.printStackTrace();
  57.         System.exit(0);
  58.     }
  59.  
  60. }
Advertisement
Add Comment
Please, Sign In to add comment