Giter Club home page Giter Club logo

java-intro-to-databases's Introduction

Database Lab

The purpose of the lab is to create an address book, that can save its data in mysql. Below is the UML that describes the structure of your project. You are expected to use Test Driven Development! However, you will not need to write unit test for the DataBase Object. (This is because unit testing databases has a trick to it! You will learn that later.)

UML

UML

Step 01 Setting up Database

  • If you did this step on monday, you do not need to do this. However if you did not will need to get the docker image loaded on to your hard drive
docker pull mysql:5.7.32

Once that is done create the docker container:

  • Before you type this in create your OWN password and replace that in the string below where you see
  • Please remove the < > symbols from your password.
  • If you have MYSQL installed on your machine change 3306:3306 with 3308:3306
docker run --name cd-address-book -p 3306:3306 -e MYSQL_ROOT_PASSWORD=<password> -d mysql:5.7.32

SSH or remote login to the container:

docker exec -it cd-address-book /bin/bash

Log in to mysql on the container:

mysql -u root -p

Display all of the databases:

show databases;

Create a new Database:

CREATE DATABASE addressbook;

Create a new user for the database

CREATE USER 'developer01' IDENTIFIED BY 'pass';

Grant privileges to the user:

GRANT ALL on addressbook.* TO 'developer01';

Point MYSQL to look at your table:

use addressbook;

Create table for Employees:

create table  IF NOT EXISTS PERSON (id VARCHAR(36), first_name VARCHAR(45), last_name VARCHAR(100), email VARCHAR(100), age INTEGER);

Exit Mysql:

quit

Exit Docker SSH:

exit

Step 02 DataBase Tips

Sample Save

// create a Statement from the connection
Statement statement = connection.createStatement();

// insert the data
statement.executeUpdate("INSERT INTO Customers " + "VALUES (1001, 'Simpson', 'Mr.', 'Springfield', 2001)");

For more information look at this link Link

Sample Read

try {
    String sql = "SELECT ID, NAME, DESIGNATION from EMPLOYEE";
    Statement stmt = connection.createStatement();
    ResultSet rs = stmt.executeQuery(sql);

    while(rs.next()){
        String name = rs.getString("NAME");
        System.out.println("Found "+ name);
    }
}catch(SQLException se) {
}

For the rest of the command you will have to do some reseach.... Good Luck!!!

java-intro-to-databases's People

Stargazers

 avatar

Watchers

 avatar  avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.