I'm currently doing a mini parking system for our JAVA bootcamp.
I'm trying to get the value of the integer variables into a different class.
These variables are results of the sql counts of total parked (countCar
,countMotor
, and countVan
).
This is what I did:
I stored them in a class called SQLCountResult
:
public class SQLConnections {
public Connection con = null;
public void parkInSQL() {
con = dbConnect.con();
int countCar;
int countMotor;
int countVan;
int parkCar;
int parkMotor;
int parkVan;
int[] vehicleTotal = new int[3];
String qCar = "SELECT COUNT(*) FROM `vehicle` WHERE `vType` = 1 AND `parkout` IS NULL";
String qMotor = "SELECT COUNT(*) FROM `vehicle` WHERE `vType` = 2 AND `parkout` IS NULL";
String qVan = "SELECT COUNT(*) FROM `vehicle` WHERE `vType` = 3 AND `parkout` IS NULL";
try {
Statement stmtCar = con.createStatement();
Statement stmtMotor = con.createStatement();
Statement stmtVan = con.createStatement();
ResultSet rsCar = stmtCar.executeQuery(qCar);
ResultSet rsMotor = stmtMotor.executeQuery(qMotor);
ResultSet rsVan = stmtVan.executeQuery(qVan);
rsCar.next();
rsMotor.next();
rsVan.next();
countCar = rsCar.getInt(1);
countMotor = rsMotor.getInt(1);
countVan = rsVan.getInt(1);
} catch(SQLException e) {
e.printStackTrace();
}
}
}
Now I want to call countCar
, countMotor
, and countVan
to another class called Park. My code for the Park class is below:
public class Park {
public Connection con = null;
public void parkMethod() {
SQLConnections sqlConnections = new SQLConnections();
sqlConnections.parkInSQL();
}
}
I also tried using extend but this didn't work either. How can I call these variables to the Park class?