Upgrading a jailbroken iPhone from 3.1.3 without data loss
I don't particularly see why you would lose your data when upgrading… but then I also don't particularly see why you'd prefer to have your 3GS on 3.2x when you could have it on 4.2x just as easily… 

Do you sync your iPhone with iTunes and use it to back up? If so, you're unlikely to have a problem. Just go to http://iclarified.com/tutorials/iphone/ and pick the tutorial that's right for your phone's situation.