public void addCustomer(Customer customer) throws CustomerHomeException,
ClassNotFoundException {
try {
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
String url = "jdbc:odbc:Mydb";
String user = "user1";
String password = "password";
Connection con = DriverManager.getConnection(url, user, password);
PreparedStatement smt = con
.prepareStatement("insert into customer (ssn,customer_name) values (?,?)");
if (this.getCustomers().equals(customer.getSocialSecurityNumber()) == false){
smt.setString(1, customer.getSocialSecurityNumber());
smt.setString(2, customer.getName());
smt.executeUpdate();
}
smt.close();
con.close();
} catch (SQLException e) {
throw new CustomerHomeException("Failed to create CustomerHome", e);
}
我们使用的密钥是 ssnumber ;我需要遍历数据库表并使用准备好的语句进行检查