Use that to introduce a restrictive clause, which is a clause that is essential to the meaning of the sentence. Use which to introduce a nonrestrictive clause, which is a clause that you can omit without affecting the meaning of the sentence. If you can insert a comma before the clause, it is nonrestrictive.