All these scripts and test data are available at www.quepublishing.com. Put 0789726718 in the search field.
package beans; import java.sql.*; import oracle.jdbc.driver.*; import java.io.*; public class CarConnection { public static Connection getConnection() throws Exception { String driverClass = "oracle.jdbc.driver.OracleDriver"; String username = "scott"; String password = "tiger"; String dburl = "jdbc:oracle:thin:@localhost:1521:dto"; Driver d = (Driver)Class.forName(driverClass).newInstance(); return DriverManager.getConnection(dburl,username,password); } } package beans; import java.sql.*; import oracle.jdbc.driver.*; import java.io.*; public class CarGetCar extends Object { private int id = 0; private String description =""; private String image =""; private String amount =""; public void setId(int id) { this.id = id; getCar(); } public int getId() { return id; } public String getDescription() { return description; } public String getImage() { return image; } public String getAmount() { return amount; } public void getCar() { try { Connection conn = CarConnection.getConnection(); CallableStatement cs = conn.prepareCall("begin get_car(?,?,?,?); end;"); cs.setInt(1,id); cs.registerOutParameter(1,Types.INTEGER); cs.registerOutParameter(2,Types.VARCHAR); cs.registerOutParameter(3,Types.VARCHAR); cs.registerOutParameter(4,Types.VARCHAR); cs.execute(); id = cs.getInt(1); description = cs.getString(2); image = cs.getString(3); amount = cs.getString(4); cs.close(); } catch (SQLException e) { id = 0; description = "Error"; image = "/Error.gif"; amount = "Error"; } catch (Exception e) { id = 0; description = "Error"; image = "/Error.gif"; amount = "Error"; } } } package beans; import java.sql.*; import oracle.jdbc.driver.*; import java.io.*; public class MakeOffer extends Object { private int id = 0; private String buyer =""; private String phone =""; private String offer = null; private String result =""; public void setId(int id) { this.id = id; } public int getId() { return id; } public void setBuyer(String buyer) { this.buyer = buyer; } public String getBuyer() { return (buyer==null) ? "" : buyer; } public void setPhone(String phone) { this.phone = phone; } public String getPhone() { return (phone==null) ? "" : phone; } public void setOffer(String offer) { this.offer = offer; } public String getOffer() { return (offer==null) ? "" : offer; } public String getResult() { makeOffer(); return result; } public void makeOffer() { if (offer != null) { try { Connection conn = CarConnection.getConnection(); CallableStatement cs = conn.prepareCall("declare x boolean; begin make_offer(?,?,?,?,x,?); end;"); cs.setInt(1,id); cs.setString(2,buyer); cs.setString(3,phone); cs.setString(4,offer); cs.registerOutParameter(5,Types.VARCHAR); cs.execute(); result = cs.getString(5); cs.close(); } catch (SQLException e) { result = "Error: "+e; } catch (Exception e) { result = "Error: "+e; } } } }
18.226.96.61