Exemplo n.º 1
0
 public void insert(Client client) throws SQLException {
   String firstName = client.getFitstName();
   String secondName = client.getSecondName();
   String email = client.getEmail();
   PreparedStatement ps =
       OracleConnection.getConnection().prepareStatement("INSERT into Client VALUES ? ,? ,? ");
   ps.setString(1, firstName);
   ps.setString(2, secondName);
   ps.setString(3, email);
   ps.executeQuery();
 }
Exemplo n.º 2
0
 public void delete(Client client) throws SQLException {
   String firstName = client.getFitstName();
   String secondName = client.getSecondName();
   PreparedStatement ps =
       OracleConnection.getConnection()
           .prepareStatement(
               "SELECT * FROM client c, good_order o WHERE c.first_name = ? and c.second_name =? join on (c.id=o.client_id)");
   ps.setString(1, firstName);
   ps.setString(2, secondName);
   ResultSet rs = ps.executeQuery();
   if (rs.first()) {
     System.out.println("This client has an order, can`t be deleted");
   } else {
     ps =
         OracleConnection.getConnection()
             .prepareStatement("DELETE FROM client WHERE first_name = ? and secind_name = ?");
     ps.setString(1, firstName);
     ps.setString(2, secondName);
     ps.executeUpdate();
   }
 }