I have a class Dresser that extends the abstract class Furniture.
This is the class Furniture.
public abstract class Furniture {
private String furnishing;
private String board;
private String wood;
private double mass;
private int price;
private int shippingPrice;
}
And this is the class Dresser.
public final class Dresser extends Furniture {
private int width;
private int length;
private int height;
private int drawers;
}
The inheritance is represented as such in the tables:
CREATE TABLE furnitures (
index INTEGER NOT NULL AUTO_INCREMENT,
furnishing VARCHAR(255) NOT NULL,
board VARCHAR(255) NOT NULL,
wood VARCHAR(255) NOT NULL,
mass FLOAT(5,2) NOT NULL,
price INTEGER NOT NULL,
shipping_price INTEGER NOT NULL,
PRIMARY KEY (index)
)
CREATE TABLE IF NOT EXISTS dressers (
index INTEGER NOT NULL,
width INTEGER NOT NULL,
length INTEGER NOT NULL,
height INTEGER NOT NULL,
drawers INTEGER NOT NULL,
PRIMARY KEY (index),
FOREIGN KEY (index) REFERENCES furniture (index)
)
I need to build a query that allows me to select a record or select all records from a table but so far I've come up with this but I don't know if it's necessarily the best way to do so.
String query =
"SELECT furniture.board, furniture.wood, furniture.mass, " +
"furniture.price, furniture.shipping_price, " +
"dresser.width, dresser.length, dresser.height, dresser.drawers " +
"FROM furniture, dresser " +
"WHERE " +
"furniture.index = dresser.index";
That would be my query to select all records (the furnishing field can be ignored safely).
How can this be improved? Also, how could I make a query to select a certain record given a certain index or how to update a record?
PD: I'm using MySQL.