-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy patha2q1sa.java
More file actions
28 lines (27 loc) · 925 Bytes
/
Copy patha2q1sa.java
File metadata and controls
28 lines (27 loc) · 925 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
import java.util.*;
import java.sql.*;
public class a2q1sa {
public static void main(String[] args) {
String url = "jdbc:postgresql://localhost:5432/java";
String user = "postgres";
String password = "12345";
try {
Class.forName("org.postgresql.Driver");
Connection con = DriverManager.getConnection(url, user, password);
Statement stmt = con.createStatement();
String Query = "SELECT * FROM students";
ResultSet rs = stmt.executeQuery(Query);
System.out.println("Students Details \nID :\t Name : \t Address : \n");
while (rs.next()) {
int id = rs.getInt("id");
String name = rs.getString("name");
String address = rs.getString("address");
System.out.println(String.format("| %s | %s | %s |", id, name, address));
}
con.close();
stmt.close();
} catch (Exception e) {
e.printStackTrace();
}
}
}