-1
             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 です。データベーステーブルを反復処理し、準備済みステートメントを使用してチェックする必要があります

4

1 に答える 1