현재 주문 시스템을 기반으로 한 프로젝트를하고 있습니다.자바에서 날짜가 잘못되었습니다
pstmt.setDate(4, (Date)orders.getOrderDate()); and states that java.util.Date cannot be cast to java.sql.Date
내 주요 :
이public static int createOrders(Orders orders) {
// declare local variables
int orderID ;
DBController db = new DBController();
String dbQuery;
PreparedStatement pstmt;
// step 1 - establish connection to database
db.getConnection();
// step 2 - declare the SQL statement
dbQuery = "INSERT INTO orders (orderId, tableNo, numPax, orderDate , totalAmount) VALUES(?, ?, ?, ? , ?)";
pstmt = (PreparedStatement) db.getPreparedStatement(dbQuery);
orderID = getNextOrderId();
// step 3 - to insert record using executeUpdate method
try {
pstmt.setInt(1,orderID);
pstmt.setInt(2, orders.getTableNo());
pstmt.setInt(3, orders.getNumPax());
pstmt.setDate(4, (Date)orders.getOrderDate());
pstmt.setDouble(5, orders.getTotalAmount());
if (pstmt.executeUpdate() == 1)
return orderID;
pstmt.close();
} catch (Exception e) {
e.printStackTrace();
}
// step 4 - close connection
db.terminate();
return -1;
}
가에 오류가있을 것입니다 :
package fourFinger.entity;
import java.util.Date;
import javax.swing.JComboBox;
public class Orders {
private int orderId;
private int tableNo ;
private int numPax;
private Date orderDate;
private double totalAmount;
public Orders(int tableNo, int numPax, Date orderDate, double totalAmount) {
super();
//this.orderId = order Id;
this.tableNo = tableNo;
this.numPax = numPax;
this.orderDate = orderDate;
this.totalAmount = totalAmount;
}
public Orders(int orderId, int tableNo, int numPax, Date orderDate, double totalAmount) {
this(tableNo, numPax, orderDate, totalAmount);
this.orderId = orderId;
}
public int getOrderId() {
return orderId;
}
public void setOrderId(int orderId) {
this.orderId = orderId;
}
public int getTableNo() {
return tableNo;
}
public void setTableNo(int tableNo) {
this.tableNo = tableNo;
}
public int getNumPax() {
return numPax;
}
public void setNumPax(int numPax) {
this.numPax = numPax;
}
public Date getOrderDate() {
return orderDate;
}
public void setOrderDate(Date orderDate) {
this.orderDate = orderDate;
}
public double getTotalAmount() {
return totalAmount;
}
public void setTotalAmount(double totalAmount) {
this.totalAmount = totalAmount;
}
내 OrdersDA 데이터베이스에 연결 : 여기에
는 "주문"에 대한 엔티티 클래스의 주문 생성시 사용 방법 :private void actionPerformedOrder() {
//retrieve user input
String numPax = (String) cbNoPax.getSelectedItem();
String tableNo= (String)cb_tableno.getSelectedItem();
Date orderDate = new Date();
orders=newOrders(Integer.parseInt(tableNo),Integer.parseInt(numPax)
,orderDate, totalAmount);
int orderID = OrdersDA.createOrders(orders);
}
내가 잘못 갔다는 아이디어가 있습니까? 귀하의 도움을 부탁드립니다!
OT : '주문'클래스를 '주문'이라고해서는 안됩니까? – Biffen