FileDocCategorySizeDatePackage
JDBCRentABike.javaAPI DocExample2823Sun Apr 24 18:53:10 BST 2005com.springbook

JDBCRentABike

public class JDBCRentABike extends org.springframework.jdbc.core.support.JdbcDaoSupport implements RentABike

Fields Summary
private String
storeName
private static final int
MANUFACTURER
private static final int
MODEL
private static final int
FRAME
private static final int
SERIALNO
private static final int
WEIGHT
private static final int
STATUS
Constructors Summary
Methods Summary
public voiddeleteBike(Bike bike)

      JdbcTemplate template = getJdbcTemplate();
      template.execute("DELETE FROM bikes where bikes.serialno = '" + bike.getSerialNo() + "'");
   
public BikegetBike(java.lang.String serialNo)

      final Bike bike = new Bike();
      JdbcTemplate template = getJdbcTemplate();
      template.query("SELECT * FROM bikes where bikes.serialno = '" + serialNo + "'",
            new RowCallbackHandler() {
               public void processRow(ResultSet rs) throws SQLException {
                  bike.setManufacturer(rs.getString(MANUFACTURER));
                  bike.setModel(rs.getString(MODEL));
                  bike.setFrame(rs.getInt(FRAME));
                  bike.setSerialNo(rs.getString(SERIALNO));
                  bike.setWeight(rs.getDouble(WEIGHT));
                  bike.setStatus(rs.getString(STATUS));
               }
            });
      return bike;
   
public java.util.ListgetBikes()



      
      final ArrayList results = new ArrayList();
      JdbcTemplate template = getJdbcTemplate();
      template.query("SELECT * FROM bikes",
            new RowCallbackHandler() {
               public void processRow(ResultSet rs) throws SQLException {
                  Bike bike = new Bike(rs.getString(MANUFACTURER),
                        rs.getString(MODEL), rs.getInt(FRAME),
                        rs.getString(SERIALNO), rs.getDouble(WEIGHT),
                        rs.getString(STATUS));
                  results.add(bike);
               }
            });
      return results;
   
public java.lang.StringgetStoreName()

      return this.storeName;
   
public voidsaveBike(Bike bike)

      JdbcTemplate template = getJdbcTemplate();
      template.execute("DELETE FROM bikes where bikes.serialno = '" + bike.getSerialNo() + "'");
      template.execute("INSERT INTO bikes (manufacturer, model, frame, serialno, weight, status) VALUES ('" + bike.getManufacturer() + "', '" + bike.getModel() + "', " + bike.getFrame() + ", '" + bike.getSerialNo() + "', " + bike.getWeight() + ", '" + bike.getStatus() + "')");      
   
public voidsetStoreName(java.lang.String name)

      this.storeName = name;