JavaScript is for client-side scripting, it cannot connect to the database. However, you can use Ajax to convey client-side request to the server-side scripting like php, jsp, or .net code-bebind, which in turn connect to the database for any database operations, the result of which will be passed back to your Ajax script through the server-side script.
Refer:
AJAX Introduction[
^]
You can ask Google for more info on Ajax implementation with specific server-side scripting.