Проект "База данных заказов"

import java.sql.*;
import java.util.Scanner;


//Создать проект "База данных заказов".
//    Создать таблицы "Товары", "Клиенты" и "Заказы".
//    Написать код для добавления новых клиентов, товаров и оформления заказов.


public class Main {
    static final String DB_CONNECTION = "jdbc:mysql://localhost:3306/bdz?serverTimezone=Europe/Kiev";

    static final String DB_USER = "Flash";
    static final String DB_PASSWORD = "*************";

    static Connection conn;

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        Scanner scclaint = new Scanner(System.in);
        Scanner sctovarn = new Scanner(System.in);
        Scanner sctovarc = new Scanner(System.in);

        try {
            try {
                conn = DriverManager.getConnection(DB_CONNECTION, DB_USER, DB_PASSWORD);

//                initDB();
                deleteMagazin("claint");
                deleteMagazin("tovar");
                deleteMagazin("zacaz");

                Tovar tovars = new Tovar();
                tovars.addTovar(maxId("tovar"),"Nokia", 220);
                tovars.addTovar(maxId("tovar"),"Samsyng", 980);
                tovars.addTovar(maxId("tovar"),"LG", 2020);
                tovars.addTovar(maxId("tovar"),"Apol", 1000);
                tovars.addTovar(maxId("tovar"),"MK", 100);

                boolean flag =true;
                while (flag == true) {
                    System.out.println();
                    System.out.println("Будем добавлять товар?");
                    System.out.println("1: Да");
                    System.out.println("2: Нет");
                    System.out.print("-> ");

                    Integer col = sc.nextInt();
                    if (col == 1) {
                        System.out.println();
                        System.out.println("Введите пожалуйста название товара");
                        System.out.print("-> ");

                        String st = sctovarn.nextLine();
                        if (st != "") {
                            System.out.println();
                            System.out.println("Введите пожалуйста стоимость товара");
                            System.out.println("-> ");

                            Integer cos = sctovarc.nextInt();
                            if (cos >= 0) {
                                tovars.addTovar(maxId("tovar"), st, cos);
                            } else {
                                System.out.println("Не верный формат числа");
                            }
                        }
                    } else {
                        flag = false;
                    }
                }

                Klient klients = new Klient();
                klients.addKlient(maxId("claint"),"Vasia");
                klients.addKlient(maxId("claint"),"Pety");
                klients.addKlient(maxId("claint"),"Kola");
                klients.addKlient(maxId("claint"),"Kisa");

                flag =true;
                while (flag == true) {
                    System.out.println();
                    System.out.println("Будем добавлять клиента?");
                    System.out.println("1: Да");
                    System.out.println("2: Нет");
                    System.out.print("-> ");

                    Integer col = sc.nextInt();
                    if (col == 1) {
                        System.out.println();
                        System.out.println("Введите пожалуйста имя нового клиента");
                        System.out.print("-> ");

                        String nuwclaint = scclaint.nextLine();
                        if (nuwclaint != "") {
                            klients.addKlient(maxId("claint"), nuwclaint);
                        }
                    } else {
                        flag = false;
                    }
                }

                System.out.println();
                flag =true;
                while (flag == true) {
                    System.out.println();
                    System.out.println("Пройдите пожалуйста авторизацию клиента");

                    viewMagazin("claint");
                    System.out.print("-> ");
                    int k = sc.nextInt();

                    if (searchId("claint", k) > 0) {
                        System.out.println();
                        boolean flag2 = true;
                        while (flag2 == true) {
                            System.out.println("Будем делать заказ?");
                            System.out.println("1: Да");
                            System.out.println("2: Нет");
                            System.out.print("-> ");

                            Integer col = sc.nextInt();
                            if (col == 1) {
                                System.out.println();
                                System.out.println("Выберите пожалуйста нужный товар");

                                viewMagazin("tovar");
                                System.out.print("-> ");
                                int t = sc.nextInt();

                                if (searchId("tovar", t) >0) {
                                    Zakaz zak = new Zakaz();
                                    zak.addZakaz(maxId("zacaz"), t, k);
                                } else {
                                    System.out.println("Нет такого товара");
                                }
                            } else {
                                flag2 = false;
                                flag = false;
                            }
                        }
                        viewMagazinZacaz(k);
                    } else {
                        System.out.println("Не верная авторизация");
                    }
                }
            } finally {
                sc.close();
                if (conn != null) conn.close();
            }
        } catch (SQLException ex) {
            ex.printStackTrace();
            return;
        }
    }

    private static void initDB() throws SQLException {
        Statement st = conn.createStatement();
        try {
            st.execute("DROP TABLE IF EXISTS Apartments");
            st.execute("CREATE TABLE Apartments (id INT NOT NULL " +
                    "AUTO_INCREMENT PRIMARY KEY, district VARCHAR(45) NOT NULL, address VARCHAR(45) NOT NULL, " +
                    " square INT NOT NULL, number INT NOT NULL, price INT NOT NULL)");
        } finally {
            st.close();
        }
    }

    private static void deleteMagazin(String nametbl ) throws SQLException {
        System.out.print("deleteMagazin");

        PreparedStatement ps = conn.prepareStatement(
                "DELETE FROM "+nametbl);
        try {
            ps.executeUpdate(); 
        } finally {
            ps.close();
        }
    }

    private static int searchId (String table, int ids) throws SQLException {
        int idv = 0;
        PreparedStatement ps = conn.prepareStatement("SELECT * FROM "+table+" where id"+table+" = ?");
        try {
            ps.setInt(1, ids);
            ResultSet rs = ps.executeQuery();

            try {
                while (rs.next()) {
                    idv = Integer.parseInt(rs.getString(1));
                }
            } finally {
                rs.close(); // rs can't be null according to the docs
            }
        } finally {
            ps.close();
        }
        return idv;
    }

    private static int maxId (String table) throws SQLException {
        String idt = "";
        int idv = 1;
        PreparedStatement ps = conn.prepareStatement("SELECT Max(id"+table+")+1 FROM "+table);
        try {
            ResultSet rs = ps.executeQuery();

            try {
                while (rs.next()) {
                    idt = rs.getString(1);
                    if (idt == null) {
                        idv = 1;
                    } else {
                        idv = Integer.parseInt(idt);
                    }
                }
            } finally {
                rs.close(); 
            }
        } finally {
            ps.close();
        }
        return idv;
    }

    private static void viewMagazin(String nametbl) throws SQLException {
        PreparedStatement ps = conn.prepareStatement("SELECT * FROM "+nametbl);
        try {
            ResultSet rs = ps.executeQuery();

            try {
ResultSet object
                ResultSetMetaData md = rs.getMetaData();

                while (rs.next()) {
                    for (int i = 1; i <= md.getColumnCount(); i++) {
                        if (i < md.getColumnCount()) {
                            System.out.print(rs.getString(i) + ": ");
                        } else {
                            System.out.print(rs.getString(i));
                        }
                    }
                    System.out.println();
                }
            } finally {
                rs.close(); 
            }
        } finally {
            ps.close();
        }
    }

    private static void viewMagazinZacaz(int idClaint) throws SQLException {
        PreparedStatement ps = conn.prepareStatement("SELECT claintName, idzacaz, tovarName, tovarCost  FROM zacaz, tovar, claint " +
                "where idclaint = ? and idclaint = zacazClaint and zacazTovar = idtovar");
        try {
            ps.setInt(1, idClaint);
            ResultSet rs = ps.executeQuery();

            try {
 ResultSet object
                ResultSetMetaData md = rs.getMetaData();

                while (rs.next()) {
                    for (int i = 1; i <= md.getColumnCount(); i++) {
                        if (i < md.getColumnCount()) {
                            System.out.print(rs.getString(i) + ": ");
                        } else {
                            System.out.print(rs.getString(i)+" $");
                        }
                   }
                    System.out.println();
                }
            } finally {
                rs.close(); 
            }
        } finally {
            ps.close();
        }
    }
}

Klient

import javax.persistence.*;
import java.sql.PreparedStatement;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;

@Entity
@Table(name = "claint")
public class Klient {
    @Id
    @GeneratedValue(strategy = GenerationType.AUTO) 
    @Column(name = "idclaint")
    private Long id;

    @Column(name = "claintName")
    private String name;

    @OneToMany(mappedBy = "zacazClaintid", cascade = CascadeType.ALL)
    private List<Zakaz> zakazK = new ArrayList<>();


    public Klient(String name) {
        this.name = name;
    }

    public Klient() {
    }

    public void addKlient(int ids,String names) throws SQLException {
        PreparedStatement ps = Mag.Main.conn.prepareStatement(
                "INSERT INTO claint ( idclaint, claintName) VALUES(?, ?)");
        try {
            ps.setInt(1, ids);
            ps.setString(2, names);
            ps.executeUpdate(); // for INSERT, UPDATE & DELETE

        } finally {
            ps.close();
        }
    }

    public Long getId() {
        return id;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }
}

Tovar

import javax.persistence.*;
import java.sql.PreparedStatement;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;

@Entity
@Table(name = "tovar")
public class Tovar {
    @Id
    @GeneratedValue(strategy = GenerationType.AUTO)
    @Column(name = "idtovar")
    private Long id;

    @Column(name = "tovarName")
    private String name;

    @Column(name = "tovarCost")
    private int cost;

    @OneToMany(mappedBy = "zacazTovarid", cascade = CascadeType.ALL)
    private List<Zakaz> zakazT = new ArrayList<>();

    public Tovar(String names, int costs) {
        this.name = names;
        this.cost = costs;
    }

    public Tovar() {
    }

    public void addTovar(int ids, String names, int cos) throws SQLException {
        PreparedStatement ps = Mag.Main.conn.prepareStatement(
                "INSERT INTO tovar ( idtovar, tovarName, tovarCost) VALUES(?, ?, ?)");
        try {
            ps.setInt(1, ids);
            ps.setString(2, names);
            ps.setInt(3, cos);
            ps.executeUpdate(); // for INSERT, UPDATE & DELETE

        } finally {
            ps.close();
        }
    }

    public Long getId() {
        return id;
    }

    public String getName() {
        return name;
    }

    public int getCost() {
        return cost;
    }

    public void setName(String name) {
        this.name = name;
    }

    public void setCost(int cost) {
        this.cost = cost;
    }

}

Zakaz

import javax.persistence.*;
import java.sql.PreparedStatement;
import java.sql.SQLException;

@Entity
@Table(name = "zacaz")
public class Zakaz {
    @Id
    @GeneratedValue(strategy = GenerationType.AUTO) // or @GeneratedValue
    @Column(name = "idzacaz")
    private Long id;

    @ManyToOne
    @JoinColumn(name = "zacazClaint")
    private Klient zacazClaintid;

    @ManyToOne
    @JoinColumn(name = "zacazTovar")
    private Tovar zacazTovarid;


    public void addZakaz(int idzakaz, int zacazTovarid, int zacazClaintid ) throws SQLException {
        PreparedStatement ps = Mag.Main.conn.prepareStatement(
                "INSERT INTO zacaz ( idzacaz, zacazTovar, zacazClaint) VALUES(?, ?, ?)");
        try {
            ps.setInt(1, idzakaz);
            ps.setInt(2, zacazTovarid);
            ps.setInt(3, zacazClaintid);
            ps.executeUpdate(); // for INSERT, UPDATE & DELETE

        } finally {
            ps.close();
        }
    }

    public Zakaz() {
    }

    public Long getId() {
        return id;
    }

    public Klient getZacazClaintid() {
        return zacazClaintid;
    }

    public Tovar getZacazTovarid() {
        return zacazTovarid;
    }
}

Предложенное вами решение верно