Код: Выделить всё
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 concatenate
// The columns here
}
} catch(SQLException e) {
System.out.println(e.getMessage());
}
}
Код: Выделить всё
private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
try {
dateRented = TFdaterented.getText();
dateReturned = TFdatereturned.getText();
payment = Double.parseDouble(TFpayment.getText());
expense = Double.parseDouble(TFexpense.getText());
pickUp = TFpu.getText();
dropOff = TFdo.getText();
customerName = TFcustname.getText();
customerNum = TFcustnum.getText();
String sql = "INSERT INTO transactions"+CarRental.ID+" VALUES(NULL, "+CarRental.ID+", ? , ? , ? , ? , ? , ? , ? , ?)";
Connector.pstmt = Connector.con.prepareStatement(sql);
Connector.pstmt.setString(1, dateRented);
Connector.pstmt.setString(2, dateReturned);
Connector.pstmt.setDouble(3, payment);
Connector.pstmt.setDouble(4, expense);
Connector.pstmt.setString(5, pickUp);
Connector.pstmt.setString(6, dropOff);
Connector.pstmt.setString(7, customerName);
Connector.pstmt.setString(8, customerNum);
} catch(SQLException e) {
System.out.println(e.getMessage());
}
}
Подробнее здесь: https://stackoverflow.com/questions/784 ... ox-problem