-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathGetStudents.java
More file actions
32 lines (25 loc) · 875 Bytes
/
GetStudents.java
File metadata and controls
32 lines (25 loc) · 875 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.*;
public class GetStudents {
public static void main(String[] args) {
try {
DriverManager.registerDriver(new com.mysql.cj.jdbc.Driver());
Connection con = DriverManager.getConnection(
"jdbc:mysql://localhost:3306/24wh1a0569_himavarsha",
"root",
"G@1315"
);
Statement stmt = con.createStatement();
ResultSet rs = stmt.executeQuery("SELECT * FROM students");
while (rs.next()) {
System.out.println(
rs.getInt("id") + "\t" +
rs.getString("name") + "\t" +
rs.getInt("age")
);
}
con.close();
} catch (SQLException e) {
e.printStackTrace();
}
}
}