-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDisplayData.java
More file actions
32 lines (31 loc) · 1.23 KB
/
DisplayData.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
import java.util.*;
import java.sql.*;
class DisplayData {
public static void main(String args[]) {
try {
int numrows = 0;
Class.forName("com.mysql.jdbc.Driver");
Connection con = DriverManager.getConnection("jdbc:mysql://localhost:3306/company", "root", "root");
Statement stm = con.createStatement();
String qry = "select * from employee order by salary desc";
ResultSet rs = 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 (SQLException e) {
System.out.println("Caught Exception:" + e);
} catch (ClassNotFoundException e) {
System.out.println("Caught Exception:" + e);
}
}
}