This demo illustrates how to build and test database access, which is based on JDBC, and uses minimal yet reasonable amount of supplementary services (connection pool, configurable connection params, simple transactions) to make it realistic.
(This generates the .project and .classpath files)
Open the Oracle SQL console. Type the following commands:
SQL> CONNECT system/Student007; SQL> CREATE USER sampleuser IDENTIFIED BY samplepassword; SQL> GRANT CONNECT, RESOURCE TO sampleuser; SQL> DISCONNECT; Exit the SQL console (type "exit"); open another console. Enter the following commands: SQL> CONNECT sampleuser/samplepassword; SQL> @D:\workspace\java-eim-demo-jdbc\src\main\resources\init.sql
Run BookmarkDAOTest as JUnit test from Eclipse and see that it is green. Comment out "@After" annotation for "tearDown()" method and run the tests again (this time they do not clean the database after each testcase).
Issue the following command in the SQL console:
SQL> SELECT title FROM bookmark;
You should see two records.
In a DOS console connect to a MySQL database as a root:
C:\> mysql -u root -pStudent007
After that, execute these MySQL commands:
create database jdbc_sample; create user 'sampleuser'@'localhost' identified by 'samplepassword'; grant all on jdbc_sample.* to 'sampleuser'@'localhost'; flush privileges; exit
Exit the session as "root". Log in as "sampleuser":
C:\> mysql -u sampleuser -psamplepassword USE jdbc_sample; CREATE TABLE bookmark ( bookmark_id BIGINT NOT NULL AUTO_INCREMENT, url VARCHAR(255) NOT NULL UNIQUE, title VARCHAR(50) NOT NULL, last_modified DATETIME, content MEDIUMTEXT, checksum BIGINT, description VARCHAR(255), PRIMARY KEY(bookmark_id));