I would like to put in and put out products from my database. Color of this products are as enums
public enum Color {
WHITE("#FFFFFF"), BLACK("#000000"), GREEN("#008000"), RED("#FF0000"), BLUE("#0000FF"), YELLOW("#FFFF00"), ORANGE("#FFA500"), PURPLE("#800080"),
GRAY("#808080");
private String color;
Color (String color){
this.color = color;
}
public String getHex() {
return color;
}
}
Here i have relation with my databases. There should be Color color not as String color. I try both options. Any suggestion how to fix it?
public List<Product> getAllProducts( ){
List<Product> products = new LinkedList<Product>();
Statement statement;
try {
statement = connection.createStatement();
query = "select * from " + tableName;
ResultSet resultSet = statement.executeQuery(query);
/* (name, price, weight, color, product count, size, material */
while(resultSet.next()) {
Long id = resultSet.getLong("id");
String name = resultSet.getString("name");
Float price = resultSet.getFloat("price");
Float weight = resultSet.getFloat("weight");
String color = resultSet.getString(("color"));
Integer productCount = resultSet.getInt("productcount");
String size = resultSet.getString("size");
String material = resultSet.getString("material");
Product product = new Product(id, name, price, weight, color, productCount, size, material);
products.add(product);
}
}
catch (SQLException e) {
e.printStackTrace();
}
}