Connecting to MySQL using

slimwhimperSoftware and s/w Development

Nov 3, 2013 (4 years and 8 months ago)


Connecting to MySQL using


Required to use
Java.sql so that
we can use
Connection and
Queries using

needed for
components used
in GUI for input
and output

Java.awt.* for
interactivity with
the GUI.

Connection class comes
from Java.sql.* library.

Used to establish a
connection with the
database and starts with
a null connection until
told to connect.

Connecting to the
database is enclosed
inside a try block to
catch exceptions in
connecting, so program
doesn’t crash and
problems can be fixed

grabs the actions from
buttons, and depending
on which button is
clicked, uses the
appropriate action.

There are only 2 types
of statements in SQL,
update type statements
and Query type

An Update statement
is used to modify the
database in some way.

Update is a simple
process, the function
returns an integer of
the number of columns
returned, or
1 if the
update failed.

A query type statement
is used when we are
retrieving data from the

A ResultSet, that
executeQuery returns,
is the data retrieved in
a 2 dimensional array
similar to the format of
a database.

A ResultSet can
contain multiple data
types. In this case, it
cannot be accessed as a
normal 2 dimensional
array and we have to
use special get
functions to retrieve the

The amount of columns
returned by a query statement
cane be retrieved using the
functions of a
ResultSetMetaData., this
holds information about the
data returned. For example:
the name of the column, how
many columns, and the SQL
data type of the column.

All data retrieved in this
program is used as strings to
be printed to the TextArea in
the GUI.

If we wanted to actually use
the data for specific purposes,
there are other functions to
get the true data type, rather
than strings. points returns a true
if there is another row of data
in the 2 dimensional array. It
also move the ResultSet to
that row for retrieval with a
ResultSetMetaData data type.