Created
October 1, 2018 03:57
-
-
Save nibro7778/a81b0babf1419386f0858ed25e061ff7 to your computer and use it in GitHub Desktop.
Test MySQL connection using JDBC
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
* To change this license header, choose License Headers in Project Properties. | |
* To change this template file, choose Tools | Templates | |
* and open the template in the editor. | |
*/ | |
package mysqlconnectiontest; | |
import java.sql.Connection; | |
import java.sql.DriverManager; | |
import java.sql.SQLException; | |
/** | |
* | |
* @author nirajtrivedi | |
*/ | |
public class MySQLConnectionTest { | |
/** | |
* @param args the command line arguments | |
*/ | |
public static void main(String[] args) { | |
// TODO code application logic here | |
String DB_DRIVER = "com.mysql.jdbc.Driver"; | |
String DB_CONNECTION = "jdbc:mysql://localhost:3306/DB_Name"; | |
String DB_USER = "root"; | |
String DB_PASSWORD = "root"; | |
Connection connection = null; | |
try { | |
Class.forName(DB_DRIVER); | |
} catch (ClassNotFoundException exception) { | |
System.out.println(exception.getMessage()); | |
} | |
try { | |
connection = DriverManager.getConnection(DB_CONNECTION, DB_USER, DB_PASSWORD); | |
System.out.println("Conncetion Successful"); | |
} catch (SQLException exception) { | |
System.out.println(exception.getMessage()); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment