FileDocCategorySizeDatePackage
JDBCRentABike.javaAPI DocExample2976Sun Apr 24 19:08:14 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 = new JdbcTemplate();
       template.setDataSource(this.getDataSource());

       class BikeHandler implements 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));
           }
       }

       template.query("SELECT * FROM bikes WHERE bikes.serialNo = '" + serialNo + "'",
                       new BikeHandler());
       return bike;
   
public java.util.ListgetBikes()



      
       final ArrayList results = new ArrayList();
       JdbcTemplate template = new JdbcTemplate();
       template.setDataSource(this.getDataSource());

       class BikesHandler implements 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);
           }
       }

       template.query("SELECT * FROM bikes", new BikesHandler());
       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;