0

我使用此命令插入一个新客户端,我在 Java 中有一个方法,我将值分配给命令:

insertNewPerson = connection.prepareStatement(
                    "INSERT INTO Addresses " + 
                    "(FirstName, LastName, Email, PhoneNumber, ClientAddress ) " +
                    "VALUES (?, ?, ?, ?, ?)" );

问题:我正在寻找类似的东西,但要删除程序文本字段中的任何条目。

这是我用来在 sql 命令中设置值的 Java 方法:

public int addPerson(
            String fname, String lname, String email, String num, String caddress)
    {
        int result = 0;

        //set parameters, then execute insertNewPerson
        try {
            insertNewPerson.setString(1, fname);
            insertNewPerson.setString(2, lname);
            insertNewPerson.setString(3, email);
            insertNewPerson.setString(4, num);
            insertNewPerson.setString(5, caddress);

            //insert the new entry; return # of rows updated
            result = insertNewPerson.executeUpdate();
        }//end try
        catch(SQLException sqlException) {
            sqlException.printStackTrace();
            close();
        }//end catch

        return result;
    }//end method addPerson
4

2 回答 2

1

据我了解,您正在寻找DELETESQL 命令:

delete from Addresses 
where FirstName = ?
and LastName = ?
and Email = ?
and PhoneNumber = ?
and ClientAddress = ?

这还考虑到您需要根据字段上的值进行删除。

于 2013-05-15T17:15:35.697 回答
1

您应该对所有记录都有一个唯一的值。如果你有一个主键,你可以使用这个块。

deletePerson = connection.prepareStatement(
    "DELETE FROM Addresses " + 
    "WHERE personID = ?" );
于 2013-05-15T18:33:56.383 回答