테이블 이름이 "쿠폰"이고 이클립스에서 java로 작업합니다.sql 코드 : SELECT * FROM 테이블 WHERE 열
getCoupon (long id) 메소드가 있습니다. 그 ID로 나에게 쿠폰을 제공하고 나는이 방법을 썼다 :
public Coupon getCoupon(long id) {
Connection con = ConnectionPool.getInstance().getConnection();
String sql = "SELECT * FROM Coupon WHERE TYPE=?";
Coupon coupon = new Coupon();
try (PreparedStatement pstmt = con.prepareStatement(sql);){
pstmt.setLong(1, id);
try (ResultSet rs = pstmt.executeQuery();) {
if (rs.next()) {
coupon.setId(rs.getLong(1));
coupon.setTitle(rs.getString(2));
coupon.setStartDate(rs.getDate(3));
coupon.setEndDate(rs.getDate(4));
coupon.setAmount(rs.getInt(5));
coupon.setType(CouponType.valueOf(rs.getString(6)));
coupon.setMessage(rs.getString(7));
coupon.setPrice(rs.getDouble(8));
coupon.setImage(rs.getString(9));
} else {
System.out.println("Coupon ID: " + id + " could not be found\n");
}
}
} catch (SQLException e) {
CouponSystemException ex = new CouponSystemException("Coupon ID: " + id + " could not be retrieved\n", e);
System.out.println(ex.getMessage());
System.out.println(e);
}
ConnectionPool.getInstance().returnConnection(con);
return coupon;
}
내가 입력입니다하여 나에게 쿠폰을 제공합니다 다른 방법을하고 싶습니다! 하지만 TYPE COLUMN은 첫 번째 열에 없으므로 예외가 발생합니다. 조언이 있으십니까?
첫 번째 조언 ... 형식 질문 –
어떤 예외가 있습니까? 행을 다른 열로 가져 오는 문제는 무엇입니까? 자세한 내용을 알려주십시오. –