Just to add a few points to Jeanne's spot-on response:
Originally posted by Ilya Elkind:
as far as i know you CAN have db connections using JS code
Client-side JavaScript cannot establish DB connections. No way. No how.
Is there a way i can call a java method in my project from an JS function?
Only via an Ajax request.
I think what i want to do is something like a MVC
Regardless of whether it's an Ajax request or not, MVC is the way to go.
If you are going to employ Ajax for this, do yourself a favor and familiarize yourself with how Ajax works, but then use a library to perform the nitty-gritty for you. Both prototype and jQuery provide top-notch Ajax support. Lately, I've been favoring the latter.