Docsity

CPSC 310 Lab 2: Modifying SimpleApp for MySQL and Derby, Lab Reports of Deductive Database Systems

Toggle sidebar
bg1
CPSC 310 Lab 2, Summer 2008, RonnieWard
Assigned 6/11/08. DUE in class on 6/25/08
1
You’ve established your ECLIPSE Java development environment, and have Ed Sciore’s
simpledb (www.cs.bc.edu/~sciore/simpledb/intro.html) running in a single ECLIPSE
project (back this up before starting this lab in case you need to refer to it again for some
reason). You have also claimed your MySQL account, and have used it in homework
exercises. You also have Derby installed on your computer and you have added the
Derby nature to Eclipse projects and used it in homework assignments. Answers on red.
The goal of this project is for you to practice JDBC client/server programming. Answer
any specific questions contained in this document, COMMENT the java code you write,
and turn it in by class time on the due date. The hardcopy you turn in should include a
signed copy of the Assignment Cover Page found on the course web site. Also, turn-in
your submission via CSNET in a single ZIP file!
0. Modify SimpleApp to work with MySQL. Download the JDBC driver for MySQL
from http://dev.mysql.com/downloads/connector/j/5.1.html. Select the “pick a mirror”
link. When asked to register to do the download, take the ‘new’ path and then near the
bottom of the shaded panel, select the link » No thanks, just take me to the downloads!
Select a mirror and download the zip file. Extract the contents, and scan the html
document: mysql-connector-java-5.1.6\docs\connector-j.html paying attention to the
installation related material. Create an Eclipse project and add the mysql-connector-java
bin file to the project build path. mysql-connector-java-5.1.6-bin Modify the
SimpleApp.java application demonstrated in class (see course website for a link to this
app so you don’t have to download the full Derby distribution to get it) to work the JDBC
driver for MySQL (this requires very simple modifications to the code).
else if (args[0].equalsIgnoreCase("mysqlclient"))
{
framework = "mysqlclient";
driver = "com.mysql.jdbc.Driver";
protocol = "jdbc:mysql://database2.cs.tamu.edu:3306/";
}
Be sure and you’re your password string from the console so that you don’t embed your
password in the source file!
props.put("user", "ward");
props.put("password", pswd);
Hint: Create the database `yourname-mysqlDB` on your MySQL account and don’t try
and create it in your JDBC program. So remove the string ‘+;create=true"’ from your
code.
String dbName = "ward-mysqlDB"; // the name of the database
Using a VPN connection, or while connected to the TAMU network, run your modified
app with a command argument of mysqlclient and turn in the associated Eclipse console
session. Also turn in your modified java code. See SimpleMySQL.java file.
SimpleMySQL starting in mysqlclient mode
Loaded the appropriate driver
Password:
xxxxxxxx
Connected to and using database ward-mysqlDB
Created table location
Inserted 1956 Webster
Inserted 1910 Union
Updated 1956 Webster to 180 Grand
pf3
pf4
pf5

Partial preview of the text

Download CPSC 310 Lab 2: Modifying SimpleApp for MySQL and Derby and more Lab Reports Deductive Database Systems in PDF only on Docsity!

Assigned 6/11/08. DUE in class on 6/25/

You’ve established your ECLIPSE Java development environment, and have Ed Sciore’s

simpledb (www.cs.bc.edu/~sciore/simpledb/intro.html) running in a single ECLIPSE

project (back this up before starting this lab in case you need to refer to it again for some

reason). You have also claimed your MySQL account, and have used it in homework

exercises. You also have Derby installed on your computer and you have added the

Derby nature to Eclipse projects and used it in homework assignments. Answers on red.

The goal of this project is for you to practice JDBC client/server programming. Answer

any specific questions contained in this document, COMMENT the java code you write,

and turn it in by class time on the due date. The hardcopy you turn in should include a

signed copy of the Assignment Cover Page found on the course web site. Also, turn-in

your submission via CSNET in a single ZIP file!

0. Modify SimpleApp to work with MySQL. Download the JDBC driver for MySQL

from http://dev.mysql.com/downloads/connector/j/5.1.html. Select the “pick a mirror”

link. When asked to register to do the download, take the ‘new’ path and then near the

bottom of the shaded panel, select the link » No thanks, just take me to the downloads!

Select a mirror and download the zip file. Extract the contents, and scan the html

document: mysql-connector-java-5.1.6\docs\connector-j.html paying attention to the

installation related material. Create an Eclipse project and add the mysql-connector-java

bin file to the project build path. mysql-connector-java-5.1.6-bin Modify the

SimpleApp.java application demonstrated in class (see course website for a link to this

app so you don’t have to download the full Derby distribution to get it) to work the JDBC

driver for MySQL (this requires very simple modifications to the code).

else if (args[0].equalsIgnoreCase("mysqlclient")) { framework = "mysqlclient"; driver = "com.mysql.jdbc.Driver"; protocol = "jdbc:mysql://database2.cs.tamu.edu:3306/"; }

Be sure and you’re your password string from the console so that you don’t embed your

password in the source file!

props.put("user", "ward"); props.put("password", pswd);

Hint: Create the database yourname-mysqlDB on your MySQL account and don’t try

and create it in your JDBC program. So remove the string ‘+;create=true"’ from your

code.

String dbName = "ward-mysqlDB"; // the name of the database

Using a VPN connection, or while connected to the TAMU network, run your modified

app with a command argument of mysqlclient and turn in the associated Eclipse console

session. Also turn in your modified java code. See SimpleMySQL.java file.

SimpleMySQL starting in mysqlclient mode Loaded the appropriate driver Password: xxxxxxxx Connected to and using database ward-mysqlDB Created table location Inserted 1956 Webster Inserted 1910 Union Updated 1956 Webster to 180 Grand

Assigned 6/11/08. DUE in class on 6/25/

Updated 180 Grand to 300 Lakeshore Verified the rows Dropped table location Committed the transaction SimpleMySQL finished

1. Writing a JDBC application. Now that you have SimpleApp working under MySQL,

work textbook exercise 8.5.1 (p. 397), parts a, c, and e (graduate students also work part f

and print and old and new price for each model). Create a yourname-newProducts

database on your MySQL account and load the tables using your JDBC application.

mysql> show databases;

| Database |

| information_schema |

| ward |

| ward-mysqlDB |

| ward-ships |

4 rows in set (0.01 sec)

mysql> create database ward-newProducts;

Query OK, 1 row affected (0.00 sec)

mysql> show databases;

| Database |

| information_schema |

| ward |

| ward-mysqlDB |

| ward-newProducts |

| ward-ships |

5 rows in set (0.01 sec)

mysql> quit;

Bye

You’ve seen how to create tables with multiple rows in the SimpleDB app

createStudentDB demonstrated in class. Turn in your java code, and a sample Eclipse

console session demonstrating your solution to each part of the problem.

a)

Exercise8_5_1 starting in mysqlclient mode Loaded the appropriate driver Password: xxxxxxxx Connected to and using database ward-newProducts Dropped table Product Created table Product

Assigned 6/11/08. DUE in class on 6/25/

2. Use the Derby server. Make your application in (#1) also work with Derby using the

derbyclient driver. Allow the app to create the database rather than creating it ahead of

time as you did in #1. Be sure and start the Derby server before you run your app. Turn in

a description of the all the changes you made to your code, and to your Eclipse project to

make this work. Turn in your modified Java code. Note: this should be a fairly simple

exercise at this point. If you have to spend a lot of time on this, then something is wrong

with your approach. In that case, contact Yue, or Philip.

a. added code to test framework for “derby” and if so, connect creating the database.

b. the sql query to find the nearest value to a given price failed on the ‘order by’ clause.

DERBY does not support the non-standard LIMIT clause, or the ORDER BY clause in

subqueries (p112 Ref Manual). The work around is to issue the two select subqueries as

separate queries using an ORDER BY clause and manually pick the first element from

the resultsets. These two values can be compared to determine the nearest model to the

given price.

c.) no change for part c of the Exercise for DERBY was required

e.) corrected a bug attempting to insert model as an int, but it was declared a char in

Product. MySQL ignored the issue, and DERBY caught it.

f.) corrected the same bug attempting to compare model as an int. MySQL ignored the

issued while DERBY caught it. Also, DERBY would not drop the table PC because there

was an open resultSet against it. Relocated finally block code and worked in the drop

statements before the connection was closed and the embedded database server was

unloaded. Again, MySQL ignored the resultSet issue. Below is a good execution.

Exercise8_5_1 starting in derbyembedded mode Loaded the appropriate driver Password: spot Connected to and using database ward-newProducts Created table Product 30 Product records inserted. Created table PC 13 PC records inserted. Starting Part a) of Exercise 8.5. Price? 1500 maker = B model = 1005 speed = 1000 price = 1499 Completed Part a) Starting Part c) of Exercise 8.5.1, pg. 364 Created table Laptop 10 Laptop records inserted. Created table Printer 7 Printer records inserted. Maker? D TYPE MODEL SPEED RAM HD RD PRICE pc 1009 1200 128 80 16xDVD 1699 pc 1010 750 64 30 40xCD 699 pc 1011 1100 128 60 16xDVD 1299 TYPE MODEL SPEED RAM HD SCREEN PRICE laptop 2007 850 128 20 15.0 3099 Completed Part c) Starting Part e) of Exercise 8.5.1, pg. 364

Assigned 6/11/08. DUE in class on 6/25/

Enter PC data on one line. Separate values using a space. Please order the data as follows: maker model speed ram hd rd price A 1116 1250 512 80 24xDVD 1199 Successfully inserted new PC into Product and PC tables Completed Part e) Starting Part f) of Exercise 8.5.1, pg. 364 New PC table with modified prices MODEL SPEED RAM HD RD PRICE 1001 700 64 10 48xCD 699 1002 1500 128 60 12xDVD 2399 1003 866 128 20 8xDVD 1899 1004 866 64 10 12xDVD 899 1005 1000 128 20 12xDVD 1399 1006 1300 256 40 16xDVD 2019 1007 1400 128 80 12xDVD 2199 1008 700 64 30 24xCD 899 1009 1200 128 80 16xDVD 1599 1010 750 64 30 40xCD 599 1011 1100 128 60 16xDVD 1199 1012 350 64 7 48xCD 699 1013 733 256 60 12xDVD 2399 1116 1250 512 80 24xDVD 1199 Completed Part f) Committed the transaction Dropped table Printer Dropped table Laptop Dropped table Product Dropped table PC Derby shut down normally Exercise8_5_1 finished

3. Use the SimpleDB server. Make your application in #1 also work with the SimpleDB

server. Remember to start the RMI service, then start the SimpleDB server. Re-call you’ll

create the ‘database’ when you start the server by supplying it as an argument to the

Eclipse run dialogue.

Several changes are needed to alter instantiating a driver, and to avoid the “operation not

implemented” error, eg. changed s.execute() to s.executeUpdate(). The connection

prepareStatement is not implemented, so to work it, we have to build dynamic sql

statements as Java strings and then executeUpdate() or executeQuery(). Tried to drop a

table that was previously created and a weird transfer of control happened to the finally

block. Gave up at this point since the simpledb coding environment is too fragile.

You will need to make changes to your Java code to use the SimpleDriver, and perhaps

other changes to accommodate SimpleDB. Again, turn in a description of the all the

changes you make to your code, and your Eclipse project to make this work. Based on

this exercise, what do you think of the SimpleDB implementation? Unable to make it

work. SimpleDB implements a very spare subset of SQL. Makes me wonder how useful

it is? Answer: It is not useful for developing db applications of any complexity, but it is

useful for its purpose—use it to learn what happens inside a database management

system, or how features of a dbms are implemented.