question: When was the incumbent first elected in the district where the result was a democratic-republican gain? 
answer: SELECT first_elected FROM table_2668401_17 WHERE result = "Democratic-Republican gain"
context: CREATE TABLE table_2668401_17 (first_elected VARCHAR, result VARCHAR)