- Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDisplayData.java
More file actions
Latest commit
32 lines (31 loc) · 1.23 KB
/
Copy pathDisplayData.java
File metadata and controls
32 lines (31 loc) · 1.23 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
importjava.util.*;
importjava.sql.*;
classDisplayData {
publicstaticvoidmain(Stringargs[]) {
try {
intnumrows = 0;
Class.forName("com.mysql.jdbc.Driver");
Connectioncon = DriverManager.getConnection("jdbc:mysql://localhost:3306/company", "root", "root");
Statementstm = con.createStatement();
Stringqry = "select * from employee order by salary desc";
ResultSetrs = stm.executeQuery(qry);
while (rs.next()) {
System.out.println(rs.getInt(1) + "\t" + rs.getString(2) + "\t" + rs.getString(3) + "\t"
+ rs.getString(4) + "\t" + rs.getInt(5) + "\t" + rs.getDouble(6));
numrows++;
}
if (numrows > 0) {
System.out.println(numrows + "rows retrieved");
} else {
System.out.println("Data not found");
}
stm.close();
rs.close();
con.close();
} catch (SQLExceptione) {
System.out.println("Caught Exception:" + e);
} catch (ClassNotFoundExceptione) {
System.out.println("Caught Exception:" + e);
}
}
}