UK Sales: 0800 035 6364 | | We'll Call You

Java & MySQL


The full documentation and information about MySQL can be found at, Alternatively, MySQL by Paul DuBois is a good reference (ISBN 0-7357-0921-1)


Test your MySQL Servlet Account is working


At this point it is assumed that the basic servlets are working. To see how to test this go to Using Servlets


To test that the connection to MySQL is working, open up a web browser and go to


http:// webserver /mountpoint / testDB2020




webserver is the name for your web server
mountpoint is the name of the mount points for servlets.


Both of these are in the account detail letter.


This should bring up a page looking like:


2020Media Database Servlet Connection Working


You have connected successfully


If this does not happen, then contact support.


Connecting to MySQL


The following code fragments show the supported method of connecting to MySQL.


import java.sql.*;


import java.util.*;

import javax.servlet.*;

import javax.servlet.http.*;


public static final String DB_URL = "jdbc\:mySQL\://db_servername/db_database";

public static final String DB_USERNAME = "db_username";

public static final String DB_PASSWORD  = "db_password";

public static final String DB_DRIVER = "";


public void init() throws ServletException






catch(java.lang.ClassNotFoundException e)






con = DriverManager.getConnection(DB_URL,



catch(SQLException ex)




db_username , db_password, db_servername and db_database are detailed in your account information.

We urge you to use code as close to this as possible, as it aids our debugging of any problems.


The source for the test page is available in the 'src' directory.


Accessing the Database


To access the database for creating tables and monitoring status, you may need to run an MySQL client. This can be done either from the command line or from your own computer.


Using the command line


There is a command line client which can be accessed by typing


mysql -u db_username -p -h db_hostname


This allows you to access the database from the command line. It is not very user friendly, but allows you to execute SQL commands directly.


You will then be prompted for your Database password. It should then return a prompt. You can then type in commands - followed by the word ';' .




    show databases;


This should return a list of databases and some information about them. More details on using MySQL can be found here.


2020Media is a leading provider of small business Wi-Fi hotspots. If you want to offer free Wi-Fi to your customers or users, our service could be exactly what you are looking for. Our Hotspots are managed in the cloud, ultra-reliable and give you loads of information about behaviour patterns of your users. Read More   Read more...
2020Media introduces Moodle Hosting - UK servers and UK Moodle experts setup your site ready to use. Read more...
Special Offer for Longer Registration Periods Register or renew a .com, .net or .org domain name for 5 years we'll include 1 year free*. Read more...
2020Media is now offering zero-click installation of the popular TYPO3 content management system. Read more...

Our blog is regularly updated with news, tips and industry opinion.


  • AggieWestons
  • baker-and-mckenzie
  • arts-council-england
  • Big Finish
  • barratt-developments-logo
  • City-of-Lincoln-council-logo
  • brora-logo
  • DenisMacShane
  • Construction-Industry-Council
  • colchester