ok..so we should never try to connect to DB directly from js...its not secured...its just bad coding...however if we have to do this we can on win platform using activeX connection
var objConnection = new ActiveXObject("adodb.connection"); .....
Other ways are connecting it to service using XMLHTTPRequest etc...this is how most of standard SAP applications communicate....