Programming Homework Object Oriented Concepts
WGU4U1971
1 | M y D B 0 9 1 5 2 0 1 0
INSTALLATION INSTRUCTIONS FOR MYSQL
DOWN LOA D A N D C ON FI G UR E MY SQL
The instructions for downloading and configuring MySQL are provided in the Course
of Study.
C R EA T IN G Y OUR DA TAB A SE FR OM A SQL SC R I PT A N D SET T IN G UP A USER A C C OUN T
After you download the registrar.sql script from TaskStream to your hard drive, follow
these steps to build your database.
Ensure your NetBeans is connected to MySQL Server and that MySQL Server is
running
2 | M y D B 0 9 1 5 2 0 1 0
SET UP USER A C C OUN T ( S)
You’ll need a user account for access to the database. This is the account that your
applications will use. Start up a cmd window in Windows and change to the bin
directory of MySQL
Start MySQL monitor from Command Prompt as root by typing in the following
command. You will need to remember the root password you created when you
configured MySQL.
mysql –h localhost –u root -p
3 | M y D B 0 9 1 5 2 0 1 0
At the mysql> prompt, type in the following three statements to create the abt1 user
account for MySQL. This is the user account that your Java application will use
when connecting to the database. The grader will also use this user account when
running your application. Be VERY careful not to make any typos.
USE mysql;
create user ‘abt1s’@’localhost’ identified by ‘abt1s’;
grant select, insert, update, delete, create, drop, references, execute on *.* to
‘abt1s’@’localhost’;
4 | M y D B 0 9 1 5 2 0 1 0
Exit.
You have added the abt1 user
Locate the SQL script on your hard drive that you downloaded from the TaskStream
instructions. It is likely named: ABT SUM 1A Registrar Attachment.sql. Rename this to
a simpler name such as registrar.sql
This script will create the registrar database and create the student table. Here is what it
looks like. You can open it up in WordPad.
Copy this script to your mysql bin directory.
Using the MySQL monitor, run the script to create your registrar database:
1. From command prompt cd to the bin directory where you placed the SQL script
2. Login as abt1s mysql –h localhost –u abt1s –p
5 | M y D B 0 9 1 5 2 0 1 0
password is abt1s
3. Execute the script source registrar.sql
4. exit
Your registrar database has been created and should appear under Databases ☺
CREAT E A CON NECT ION T O Y OUR R EG I ST R A R DAT ABASE
Right mouse click the registrar database and then select “Connect”.
You will now see the connection to your registrar database.
6 | M y D B 0 9 1 5 2 0 1 0
If you expand this connection, you will see that your Student table has been created.
There are no records in this table yet, but it is ready for your application to add student
records, query existing student records, delete records, and update records.
7 | M y D B 0 9 1 5 2 0 1 0
If you right mouse click the table, you can select the “View Data” command which will
execute a SQL query on all records in this table
Here is the ‘student’ table that got created when you ran the SQL script. All required
fields were created. There are no records in the table yet, but it is ready for records to be
added by your Java application.
8 | M y D B 0 9 1 5 2 0 1 0
CREATING YOUR JAVA APPLICATIO N
Now you are ready to develop your Java application that connects to the database and
adds, deletes, updates, or queries records in your database, according to the task’s
stated requirements. First plan your application and determine the type of user
interface you want to provide. If you develop this application in NetBeans, you will
need to include the JDBC .jar file in order for your application to connect to the database
when you run it. This is covered in the next section, “JDBC”.
JDBC
JDBC now comes with NetBeans. In order for your Java application to connect to the
database, you have to set the properties of your Java Project; so that it uses JDBC to
connect to the database. When you have coded your Java application that actually uses
JDBC to execute updates and queries, you’ll need to set your project to use the JDBC
connector for MySQL.
Right mouse click the Project folder and go to Properties.
Select Libraries category. On the far right, select Add Jar/Folder. You will then browse
to the JDBC mySql connector. This connector is now located in NetBeans
ide\modules\ext directory. You do not need to download a separate connect as we
have done in the past. Here is the path to mine:
C:\Program Files\NetBeans 6.9\ide\modules\ext\mysql-connector-
java-5.1.6-bin.jar
9 | M y D B 0 9 1 5 2 0 1 0
Good luck ☺