-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmy.java
More file actions
22 lines (19 loc) · 693 Bytes
/
my.java
File metadata and controls
22 lines (19 loc) · 693 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
import java.sql.*;
public class my {
public static void main(String[] args) {
try {
Connection con = DriverManager.getConnection(
"jdbc:mysql://localhost:3306/school", "root", "root@123");
Statement st = con.createStatement();
ResultSet rs = st.executeQuery("SELECT * FROM students");
while (rs.next()) {
System.out.println("ID: " + rs.getInt(1));
System.out.println("Name: " + rs.getString(2));
System.out.println("Age: " + rs.getInt(3));
}
con.close();
} catch (Exception e) {
e.printStackTrace();
}
}
}