Code is always the same because Java take care of backward compatibility.
Here you have tutorial about connection to database.
They explain every line of code what is made for.
Read that and I think you will not have any problems in future.
Kind regards, Mike.
my advice: learn to write your persistency code in such a way that it's not db dependent. it's much easier to work if on changing a db, all you need to do is change one single property, and not your actual code.
^ like he said.
For learning, unles you are already a MySQL admin fiend, I can recommend using the JavaDB that came with your JDK, and NetBeans which has support for JavaDB burned in to its "services" tab. Setting up a database server isn't trivial unless you already know how how to do it. Using NetBeans/JavaDB will enable you to concentrate on your Java. Later you can change the connect statement to work with MySQL or whatever - the rest of the Java SQL support is database-independent.
Just saw milil's post -
Beware that tutorial if you want current info. It starts with classForName, which became obsolete in 2006 (if not earlier).
Telling you to use classForName is a dead give-away for a tutorial that's not been updated for years and years.