In Virginia, it may be possible to get treatment in jail through a grant from the Virginia Department of Criminal Justice Services.
If you are offered court-ordered rehab in lieu of jail time, you may be able to attend a rehab program instead of serving time.