Spaces:
Sleeping
Sleeping
File size: 2,000 Bytes
fc9a733 ec4d503 fc9a733 ec4d503 fc9a733 ec4d503 fc9a733 ec4d503 fc9a733 ec4d503 fc9a733 ec4d503 fc9a733 ec4d503 fc9a733 |
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 44 45 46 47 48 49 |
// package com.cs102.attendance.controller;
// import org.springframework.beans.factory.annotation.Autowired;
// import org.springframework.http.ResponseEntity;
// import org.springframework.web.bind.annotation.GetMapping;
// import org.springframework.web.bind.annotation.RequestMapping;
// import org.springframework.web.bind.annotation.RestController;
// import javax.sql.DataSource;
// import java.sql.Connection;
// import java.sql.SQLException;
// import java.util.HashMap;
// import java.util.Map;
// @RestController
// @RequestMapping("/api/health")
// public class HealthController {
// @Autowired
// private DataSource dataSource;
// @GetMapping("/database")
// public ResponseEntity<Map<String, Object>> checkDatabaseConnection() {
// Map<String, Object> response = new HashMap<>();
// try (Connection connection = dataSource.getConnection()) {
// // Test the connection
// boolean isValid = connection.isValid(5); // 5 second timeout
// if (isValid) {
// response.put("status", "UP");
// response.put("database", "Connected");
// response.put("url", connection.getMetaData().getURL());
// response.put("driver", connection.getMetaData().getDriverName());
// response.put("version", connection.getMetaData().getDatabaseProductVersion());
// return ResponseEntity.ok(response);
// } else {
// response.put("status", "DOWN");
// response.put("database", "Connection invalid");
// return ResponseEntity.status(503).body(response);
// }
// } catch (SQLException e) {
// response.put("status", "DOWN");
// response.put("database", "Connection failed");
// response.put("error", e.getMessage());
// return ResponseEntity.status(503).body(response);
// }
// }
// } |