-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathBusDAO.java
32 lines (27 loc) · 911 Bytes
/
BusDAO.java
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
package Bus_Reservation;
import java.sql.*;
public class BusDAO {
public void displayBusInfo() throws SQLException {
String query = "Select * from bus";
Connection con = DbConnection.getConnection();
Statement st = con.createStatement();
ResultSet rs = st.executeQuery(query);
while(rs.next()) {
System.out.println("Bus No: " + rs.getInt(1));
if(rs.getInt(2)==0)
System.out.println("AC: no ");
else
System.out.println("AC: yes ");
System.out.println("Capacity: " + rs.getInt(3));
}
System.out.println("------------------------------------------");
}
public int getCapacity(int id) throws SQLException {
String query = "Select capacity from bus where id=" + id;
Connection con = DbConnection.getConnection();
Statement st = con.createStatement();
ResultSet rs = st.executeQuery(query);
rs.next();
return rs.getInt(1);
}
}