|
6
DBConnection.java
1
package com.dgu.sql401;
2
import java.sql.*;
3
4
/**
5
* Programm_name : DBConnection.java
6
* Student_id: 2019213004 Name: Yoo Kiryoung
7
* Start Date: 2021/10/04
8
* Question 401: Find all students from sql_401 table.
9
* Purpose: Check driver loading and connection to DBMS
10
*/
11
12
public class DBConnection {
13
public static void main(String[] args) {
14
// TODO Auto-generated method stub
15
String URL = "jdbc:mysql://localhost:3306/sql_401";
16
Connection con = null;
17
18
try {
19
Class.forName("com.mysql.cj.jdbc.Driver");
20
} catch(ClassNotFoundException e) {
21
System.err.println("Class Not Found :" + e.getMessage());
22
}
23
try {
24
con = DriverManager.getConnection(URL, "root", "ahepf1245780!");
25
System.out.println("Succesfully connected to DBMS!");
26
con.close();
27
} catch(SQLException e) {
28
System.err.println("SQL Error :"+ e.getMessage());
29
}
30
31
}
32
33
}
34
35