-
Notifications
You must be signed in to change notification settings - Fork 9
Expand file tree
/
Copy pathConnectionDB.java
More file actions
27 lines (20 loc) · 795 Bytes
/
ConnectionDB.java
File metadata and controls
27 lines (20 loc) · 795 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
// This program demonstrates how to connect to the my sql database
// export CLASSPATH=/Users/harshitkrvishwakarma/Desktop/Java-Programs/bin/mysql-connector-java-8.0.27.jar:$CLASSPATH
package src.college.understanding_DBConnectivity;
import java.sql.*;
public class ConnectionDB {
public static void main(String[] args) {
Connection con = null;
try {
// Connection data
String url = "jdbc:mysql://localhost:3306/test";
String user = "root";
String password = "";
Class.forName("com.mysql.cj.jdbc.Driver");
con = DriverManager.getConnection(url, user, password);
System.out.println("Success" + con);
} catch (Exception e) {
System.out.println(e);
}
}
}