xXolitudEe

Untitled

Jun 23rd, 2018
84
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.71 KB | None | 0 0
  1. package sqlmain;
  2.  
  3. import java.sql.Connection;
  4. import java.sql.DriverManager;
  5. import java.sql.SQLException;
  6.  
  7. public class SqlTest {
  8.  
  9.     /* URL: jdbc:mysql://hostname:port/database */
  10.     private static final String url = "jdbc:mysql://localhost:3306/dummy";
  11.    
  12.     private static final String user = "root";
  13.     private static final String pass = "admin";
  14.    
  15.     public static void main(String[] args) {
  16.         System.out.println("Connecting to DB...");
  17.        
  18.         /* Connection test to DB */
  19.         try (Connection connection = DriverManager.getConnection(url, user, pass)) {
  20.             System.out.println("Connected!");
  21.         } catch (SQLException e) {
  22.             System.err.println(String.format("Something went wrong: %s", e.getMessage()));
  23.         }
  24.     }
  25. }
Add Comment
Please, Sign In to add comment