So what do you need the variable for? I'd really implement a sequence using stored procedures if I were you. It's best to keep the logic in the database and not the client application. More security and less data transfer (thus better speed).