-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDatabaseConnection.java
More file actions
43 lines (26 loc) · 972 Bytes
/
DatabaseConnection.java
File metadata and controls
43 lines (26 loc) · 972 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
33
34
35
36
37
38
39
40
41
42
43
package ExpenseTracker;
import java.sql.Connection;
import java.sql.DriverManager;
public class DatabaseConnection {
static final String URL = "jdbc:mysql://localhost:3306/expense_tracker";
static final String USER = "root";
static final String PASSWORD = "your_password";
public static Connection getConnection() {
Connection con = null;
try {
con = DriverManager.getConnection(URL, USER, PASSWORD);
} catch (Exception e) {
System.out.println("Connection Failed: " + e.getMessage());
}
return con;
}
// Main method to test database connection
public static void main(String[] args) {
Connection con = getConnection();
if (con != null) {
System.out.println("Database Connected Successfully!");
} else {
System.out.println("Database Connection Failed!");
}
}
}