Yes there is a better way.
The standard approach to database connections now is to use a JNDI datasource.
Basically your code looks up the Datasource from JNDI, and then invokes the 'getConnection()' method on it.
Your code need know nothing about where the database is, or what the username/password connection details are.
Seeing as you are using JSP, a link to the
Tomcat JNDI Datasources may be appropriate.
b. what does the url - jdbc:mysql://localhost:3306/ represent and how do ppl come up with this URL.
The first bit is protocol: jdbc
The second bit tells it what database/driver: mysql
The next bit is the address of the server (in this case localhost, meaning the current computer)
The final bit is the port number to talk to the database on. This is a configuration feature on your database.
The URL is obtained from looking at your documentation for your database :-)
c. Isnt there a jar called smthing like mySQLConnector.jar - how does that work? Can I just copy that jar from some safe site add it to the project? How to update the username and password in that case?
Yes there is such a jar.
You get it from the MySQL site and add it to your project.
For a web application, you normally install it on your application server /lib directory so you can use it with JNDI.