or download this
my $dbh = DBI->connect($dsn, $usr, $pwd, {RaiseError => 1});
my $sth = $dbh->prepare("insert into Customers(Names, ...) values(?, .
+..)");
...
# Handle this the same way that you would handle the
# case where your checkDuplicateName() returns true
}