-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMyConnection1.java
More file actions
37 lines (34 loc) · 1.09 KB
/
Copy pathMyConnection1.java
File metadata and controls
37 lines (34 loc) · 1.09 KB
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
28
29
30
31
32
33
34
35
36
37
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
import java.util.logging.Level;
import java.util.logging.Logger;
public class MyConnection
{
public static Connection getConnection() throws SQLException
{
Connection con = null;
try
{
Class.forName("com.mysql.cj.jdbc.Driver");
con = DriverManager.getConnection("jdbc:mysql://localhost/gym","root","Admin");
System.out.println("Connected With the database successfully");
}
catch(ClassNotFoundException ex)
{
Logger.getLogger(MyConnection.class.getName()).log(Level.SEVERE, null, ex);
}
return con;
}
}
/*import java.sql.*;
class MyConnection{
public static void main(String[] args) {
try {
Connection connection = DriverManager.getConnection("jdbc.:mysql://localhost/gym","root","Admin");//Establishing connection
System.out.println("Connected With the database successfully");
} catch (SQLException e) {
System.out.println("Error while connecting to the database");
}
}
}*/