|
select_test.java
1
2
3
4
5
* Programm_name : select_test.java
6
* Student_id: 2019213004 Name: Yoo Kiryoung
7
8
* Question 401: Find all students from sql_401 table.
9
* Purpose: search student table. (select*from student)
10
11
12
public class select_test {
13
14
public static void main(String[] args) {
15
String url =
"jdbc:mysql://127.0.0.1/sql_401?useSSL=false&user=root&password=ahepf1245780!";
16
Connection conn = null;
17
Statement stmt = null;
18
19
ResultSet rs = null; //ResultSet object
20
21
22
try {
23
Class.forName("com.mysql.cj.jdbc.Driver");
24
25
26
conn = DriverManager.getConnection(url);
27
28
29
stmt = conn.createStatement();
30
String selectSql = "SELECT * FROM student;";
31
//stmt.executeQuery(sql);
32
33
34
rs = stmt.executeQuery(selectSql); //insert result of executeQuery into rs
35
System.out.println("\n?й?: 2019213004 \t
???:????? \t ???:2021.10.05 "+"\n"+
"???? 401 : ??? ?л??? ???????."+"\n"+"sql_401: select*from student"+"\n"+"??????:"+"\n");
36
System.out.println("ID \t NAME \t DEPT_NAME \t TOT_CRED");
37
38
while(rs.next())
39
{
40
System.out.println
41
(
42
rs.getString("ID") + "\t" +
43
rs.getString("name") + "\t" +
44
rs.getString("dept_name") +"\t"+
45
rs.getString("tot_cred")
46
);
47
}
48
49