This is the basis of it, you'll need to know the name of the MYSQL driver your host is using and change it accordingly.
You'll also need to know the URL of the database, this should also be available from your host.
You can plug this into any Servlet or JSP
Firstly import java.sql.*; into your program, along with whatever else your importing.
//Credentials for connecting to database
String url = "jdbc:mysql://someurl";
String user = "username;
String pass = "password";
//Attempt connection & catch any errors that occur
Class.forName( "org.gjt.mm.mysql.Driver" );//MySQL driver
connection = DriverManager.getConnection(url, user, pass );
catch ( ClassNotFoundException cnfex )
System.err.println( "Failed to load JDBC/ODBC driver." );
System.exit( 1 ); // terminate program
catch ( SQLException sqlex )
System.err.println( "Unable to connect" );