How to prevent back pain from working on a computer all day?

Posture, stretching. Make sure your posture is good while sitting and that your workstation is set up for someone your height. See osha web site for recommendations: https://www.Osha.Gov/sltc/etools/computerworkstations/index.Html. Also, get up and stretch every hour and do stretches while seated at your desk.
Frequent breaks. I recommend you get up and stretch once per hour for five minutes. In addition, strengthening and stretching your back after work will help reduce your pain while at work. To do this, try yoga or pilates combined with gentle aerobic exercise. Finally, if this doesn't help, there are special desks made to work at while standing.