DizzyFoxkit

DBDemo

Jan 25th, 2016
53
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.20 KB | None | 0 0
  1. import java.sql.*;
  2. import java.util.Properties;
  3.  
  4.  
  5. public class DBDemo {
  6.     // The JDBC Connector Class.
  7.     private static final String dbClassName = "com.mysql.jdbc.Driver";
  8.     // Connection String. Emotherearth is the database the program is
  9.     // connecting to. You can include user and password after this by adding
  10.     // (say) ?user=paulr&passowrd=pualr. Not recomended!
  11.     private static final String CONNECTION =
  12.         "jdbc:mysql://127.0.0.1/emotherearth";
  13.     public static void main(String[] cl_args) throws
  14.         ClassNotFoundException, SQLException
  15.         {
  16.             System.out.println(dbClassName);
  17.             // Class.forName(xxx) loads the jdbc classes and creates
  18.             // a drivermanager class factory
  19.             Class.forName(dbClassName);
  20.             // Properties for user and password. Here the user and password are xellophane and 'Gr3yh@t'
  21.             Properties p = new Properties();
  22.             p.put("user", "xellophane");
  23.             p.put("password", "Gr3yh@t");
  24.             // Now try to connect
  25.             Connection c = DriverManager.getConnection(CONNECTION, p);
  26.             System.out.println("It works! ");
  27.             c.close();
  28.         }
  29. }
Add Comment
Please, Sign In to add comment