Guest User

Untitled

a guest
Jul 22nd, 2018
242
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.88 KB | None | 0 0
  1. import java.sql.*;
  2. import java.util.Scanner;
  3.  
  4. public class Connect {
  5.    
  6.     public static void main(String[] args) {
  7.         //Gets user's name and pass.
  8.         Scanner in = new Scanner(System.in);
  9.         System.out.println("User Name: ");
  10.         GlobalDataStore.User_Name = in.nextLine();
  11.         System.out.println("Password: ");
  12.         GlobalDataStore.Password = in.nextLine();
  13.        
  14.         //Connects to database with user name and pass.
  15.         System.out.println("MySql Connect Example");
  16.         Connection conn = null;
  17.         String url = "jdbc:mysql://localhost:3306/";
  18.         String dbName = "Horde";
  19.         String driver = "com.mysql.jdbc.Driver";
  20.        
  21.         String password = "GlobalDataStore.Password";
  22.        
  23.         try{
  24.             Class.forName(driver).newInstance();
  25.             conn = DriverManager.getConnection(url+dbName,userName,password);
  26.             System.out.println("Connected to the database");
  27.         } catch (Exception e) {
  28.             e.printStackTrace();   
  29.         }
  30.        
  31.     }
  32.  
  33. }
Add Comment
Please, Sign In to add comment