-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPatientInf0.java
More file actions
42 lines (34 loc) · 1.53 KB
/
PatientInf0.java
File metadata and controls
42 lines (34 loc) · 1.53 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
38
39
40
41
42
import java.sql.*;
public class PatientInfo {
public static void main(String[] args) {
try {
// Step 1: Load the JDBC driver
Class.forName("oracle.jdbc.driver.OracleDriver");
// Step 2: Establish a connection
Connection connection = DriverManager.getConnection(
"jdbc:oracle:thin:@localhost:1521:xe", "bhagiradhija", " ");
// Step 3: Create a statement
Statement statement = connection.createStatement();
// Step 4: Execute the query
ResultSet resultSet = statement.executeQuery("SELECT patient_id, name, problem, bill FROM patients");
// Step 5: Process the results
while (resultSet.next()) {
int patientId = resultSet.getInt("patient_id");
String name = resultSet.getString("name");
String problem = resultSet.getString("problem");
double bill = resultSet.getDouble("bill");
System.out.println("Patient ID: " + patientId);
System.out.println("Name: " + name);
System.out.println("Problem: " + problem);
System.out.println("Bill: " + bill);
System.out.println("--------------------------------------");
}
// Step 6: Close the connection
resultSet.close();
statement.close();
connection.close();
} catch (Exception e) {
System.err.println("Error: " + e.getMessage());
}
}
}