How to update to ios 5.1.1 without wiping it or losing the jailbreak?

I have a iPhone 3gs running ios 3 and its jailbroken unlocked. I want to update it but need to keep it jailbroken. How can i update it to ios 5.1.1 without wiping it or losing the jailbreak

I'm pretty sure that you can't do this.

But something you could try is to download an already jailbroken ios 5.1.1 software file and install it via a jailbreak program such as redsn0w. (I'm not sure if this is possible)

Not possible, without losing the jailbreak.

I had the same problem as you as the jailbreak of my iPhone was being lost every time I updated my iPhone. I finally got it permanently factory unlocked at: http://www.iphonefort-mobile.com/ The unlock took a few hours for them to complete.

First of all, its its impossible for you update your 3GS to iOS 5.1.1 because it is not the latest firmware. Unless you have saved your SHSH blobs for 5.1.1 you can't get 5.1.1 on your 3GS. You can however preserve your baseband (modem firwmare) using sn0wbreeze and creating a custom ipsw. Or if you have used the Gevey sim to unlock your iPhone, then you will not need to worry about you losing your unlock.