I’m currently developing a Car Rental System (just for fun and practice) and my problem is when I choose a car in my “Add Transaction” feature, it should be adding the transaction to the selected item, but the selected item is queried using the CONCAT function.
`private void updateCombo(){
try{
String sql = "SELECT CONCAT(carplate,' ',carbrand,' ',carname,' ',yrmodel) AS concated FROM cars WHERE idusers='"+CarRental.ID+"'";
Connector.pstmt = Connector.con.prepareStatement(sql);
Connector.rs = Connector.pstmt.executeQuery();
while(Connector.rs.next()){
DBcar.addItem(Connector.rs.getString("concated"));
// Used Concated so since you cannot manually concatinate
// The columns here
}
}catch(SQLException e){
System.out.println(e.getMessage());
}`
and this updateCombo() function is stored on the class constructor, I’m wondering what I can do so that what car the user chooses to input all this information can be selected properly using the ActionPerformed of the comboBox. Here’s a preview of the “Add Transaction” feature of my system
The only thing that makes sense to me is I remove the CONCAT and just simply add the car plate so that it’d be easier to code but it would look better and easier if the user could just see the model along with it.
user24935907 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.