Best way to access your database is using server-side language. You can then pass the results to your javascript code either via html object, or through writing the variable assignment directly to the page (response.write in ASP).
If you need the info in Javascript to process it then you will need to set up your Javascript to be parsed on the server to do server side substitutions via your chosen server side language before the script is downloaded to the browser. You can force this for external javascripts by changing the file extension eg:
Bookmarks