这样才合适: public Customer getCustomer(){ return New Customer(); } public List getCustomerProducts(){ return New Vector(); }
返回值也写错了,应是customer,你要不想实现,改成abstract public abstract class Model{ public abstract customer getCustomer(); public abstract List getCustomerProducts(); }
我现在把源代码贴出啦!源代码很长,我只是贴一部分,请大家给分析一下!!! package fgh27; import fgh27.*; import java.io.*; import java.sql.*; import java.util.*;/** *a person or company that has bought LyricNote productocts. */ public class Customer implements Serializable { private String customerID; private String name; private String phone; /** *factory method to create a customer record from the current row of a result cet * @param rs a result set from the customer table * @exception SQLException if a database error occurs */ public static Customer load(ResultSet rs)throws SQLException { Customer customer=new Customer(); String value=null; value=rs.getString(1); if(value!=null) customer.setCustomerID(value); value=rs.getString(2); if(value!=null) customer.setName(value); value=rs.getString(3); if(value!=null) customer.setPhone(value); return customer; } /** *returns the object as a CSV string */ public String toString() { StringBuffer sb=new StringBuffer(); Util util=new Util(); if(getCustomerID()!=null) sb.append(util.quote(getCustomerID())); sb.append(","); if(getName()!=null) sb.append(util.quote(getName())); sb.append(","); if(getPhone()!=null) sb.append(util.quote(getPhone())); return sb.toString(); } //======================== //Property accessor methods //======================== /** * returns the customerID */ public String getCustomerID() {return customerID;} /** *sets the customerID * @param customerID the customerID */ public void setCustomerID(String customerID) {this.customerID=customerID;} public String getName() {return name;} public void setName(String name) {this.name=name;} public String getPhone() {return phone;} public void setPhone(String phone) {this.phone=phone;} } public class Model implements Serializable { public Customer getCustomer()throws SQLException { //verify that a connection exists if(!isConnected()) throw new SQLException ("No connection"); if(customerID==null) throw new SQLException ("NO customer id"); PreparedStatement pstmt=null; ResultSet rs=null; Customer customer=null; try { //prepare the query SQL pstmt=con.prepareStatement("select * from customers where customerID=?"); pstmt.setString(1,customerID); //execute the query rs=pstmt.executeQuery(); if(rs.next()) customer=Customer.load(rs); } finally{ if(rs!=null) rs.close(); if(pstmt!=null) pstmt.close(); } //return the customer return customer; } ublic List getCustomerProducts()throws SQLException { //verify that a connection exists if(!isConnected()) throw new SQLException("No connected"); //verify that customer ID exists if(customerID==null) throw new SQLException("No customer ID"); PreparedStatement pstmt=null; ResultSet rs=null; List list=null; try{ //prepare the query SQL pstmt=con.prepareStatement("select *"+"from custprod"+"where customerID=?"+"order by datePurchased desc"); pstmt.setString(1,customerID); rs=pstmt.executeQuery(); list=new LinkedList(); while(rs.next()) list.add(CustomerProduct.load(rs)); } finally { if(rs!=null) rs.close(); if(pstmt!=null) pstmt.close(); } //return the list return list; } }
public Customer getCustomer(){
return New Customer();
}
public List getCustomerProducts(){
return New Vector();
}
public abstract class Model{
public abstract customer getCustomer();
public abstract List getCustomerProducts();
}
package fgh27;
import fgh27.*;
import java.io.*;
import java.sql.*;
import java.util.*;/**
*a person or company that has bought LyricNote productocts.
*/
public class Customer implements Serializable
{
private String customerID;
private String name;
private String phone;
/**
*factory method to create a customer record from the current row of a result cet
* @param rs a result set from the customer table
* @exception SQLException if a database error occurs
*/
public static Customer load(ResultSet rs)throws SQLException
{
Customer customer=new Customer();
String value=null;
value=rs.getString(1);
if(value!=null)
customer.setCustomerID(value);
value=rs.getString(2);
if(value!=null)
customer.setName(value);
value=rs.getString(3);
if(value!=null)
customer.setPhone(value);
return customer;
}
/**
*returns the object as a CSV string
*/
public String toString()
{
StringBuffer sb=new StringBuffer();
Util util=new Util();
if(getCustomerID()!=null)
sb.append(util.quote(getCustomerID()));
sb.append(",");
if(getName()!=null)
sb.append(util.quote(getName()));
sb.append(",");
if(getPhone()!=null)
sb.append(util.quote(getPhone()));
return sb.toString();
}
//========================
//Property accessor methods
//========================
/**
* returns the customerID
*/
public String getCustomerID()
{return customerID;}
/**
*sets the customerID
* @param customerID the customerID
*/
public void setCustomerID(String customerID)
{this.customerID=customerID;}
public String getName()
{return name;}
public void setName(String name)
{this.name=name;}
public String getPhone()
{return phone;}
public void setPhone(String phone)
{this.phone=phone;}
}
public class Model implements Serializable
{
public Customer getCustomer()throws SQLException
{
//verify that a connection exists
if(!isConnected())
throw new SQLException ("No connection");
if(customerID==null)
throw new SQLException ("NO customer id");
PreparedStatement pstmt=null;
ResultSet rs=null;
Customer customer=null;
try
{
//prepare the query SQL
pstmt=con.prepareStatement("select * from customers where customerID=?");
pstmt.setString(1,customerID);
//execute the query
rs=pstmt.executeQuery();
if(rs.next())
customer=Customer.load(rs);
}
finally{
if(rs!=null)
rs.close();
if(pstmt!=null)
pstmt.close();
}
//return the customer
return customer;
}
ublic List getCustomerProducts()throws SQLException
{
//verify that a connection exists
if(!isConnected())
throw new SQLException("No connected");
//verify that customer ID exists
if(customerID==null)
throw new SQLException("No customer ID");
PreparedStatement pstmt=null;
ResultSet rs=null;
List list=null;
try{
//prepare the query SQL
pstmt=con.prepareStatement("select *"+"from custprod"+"where customerID=?"+"order by datePurchased desc");
pstmt.setString(1,customerID);
rs=pstmt.executeQuery();
list=new LinkedList();
while(rs.next())
list.add(CustomerProduct.load(rs));
}
finally
{
if(rs!=null)
rs.close();
if(pstmt!=null)
pstmt.close();
}
//return the list
return list;
}
}