-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdb.java
More file actions
32 lines (27 loc) · 792 Bytes
/
Copy pathdb.java
File metadata and controls
32 lines (27 loc) · 792 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
28
29
30
31
32
import java.sql.Connection;
import java.sql.DriverManager;
import java.text.SimpleDateFormat;
import javax.swing.JOptionPane;
import java.util.Calendar;
import java.util.Date;
public class db {
Connection conn = null;
public static Connection dbConnector()
{
try
{
Date date = Calendar.getInstance().getTime();
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
Class.forName("com.mysql.jdbc.Driver");
Connection conn = DriverManager.getConnection("jdbc:mysql://localhost:3306/myhrdb", "root", "admin");
JOptionPane.showMessageDialog(null, "Connection Successful");
JOptionPane.showMessageDialog(null, "Today is : " + sdf.format(date));
return conn;
}
catch (Exception e)
{
JOptionPane.showMessageDialog(null, e);
return null;
}
}
}