Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/mysql/68.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 程序不会打印数据库中的所有值_Java_Mysql_Collections - Fatal编程技术网

Java 程序不会打印数据库中的所有值

Java 程序不会打印数据库中的所有值,java,mysql,collections,Java,Mysql,Collections,readAllItemsFromDb.java public List<Item> readAllItemsFromDb() { // TODO Auto-generated method stub con=(Connection)DatabaseConnectionManager.conn; Statement statement = null; try {

readAllItemsFromDb.java

public List<Item> readAllItemsFromDb() {
            // TODO Auto-generated method stub
            con=(Connection)DatabaseConnectionManager.conn;

             Statement statement = null;
                try {
                    statement = con.createStatement();
            } catch (SQLException e1) {
                // TODO Auto-generated catch block
                e1.printStackTrace();
            }
                String s = "SELECT * FROM cheese_tbl";

                try {
                    ResultSet srs = statement.executeQuery(s);
                    while(srs.next())
                    {
                        Cheese cheese = new Cheese();
                        cheese.setId(srs.getInt("id"));
                        cheese.setDescription(srs.getString("description"));
                        cheese.setWeight(srs.getFloat("weight"));
                        cheese.setPrice(srs.getFloat("price"));
                        cheese.setManufacturingDate(srs.getDate("mfg_date"));
                        cheese.setUseBeforeMonths(srs.getInt("UsebeforeInmonths"));

                        if(srs.getString("CheeseType").equals("Mozzarella"))
                            cheese.setCheeseType(CheeseType.Mozzarella);             
                        else if(srs.getString("CheeseType").equals("Easy_Spread"))
                            cheese.setCheeseType(CheeseType.Easy_Spread);
                        else if(srs.getString("CheeseType").equals("Cottage"))
                            cheese.setCheeseType(CheeseType.Cottage);            
                        else if(srs.getString("CheeseType").equals("Cheddar"))
                            cheese.setCheeseType(CheeseType.Cheddar);
                        Map<Ingred,Float> map = new HashMap<Ingred,Float>();
                        map.put(Ingred.protein,srs.getFloat("protein"));
                        map.put(Ingred.vitamin,srs.getFloat("vitaminB1"));
                        map.put(Ingred.fat,srs.getFloat("fat"));

                        cheese.setCalorieTable(map);

                        CheeseList.add(cheese);
                    }
                    System.out.println(CheeseList);
                } catch (SQLException e) {
                    // TODO Auto-generated catch block
                    e.printStackTrace();
                }

        return null;
    }
Ingred.java

package com.bean;

import java.util.HashMap;
import java.util.Map;

public class Cheese extends Item {
    public CheeseType cheeseType ;
    public Map<Ingred,Float> calorieTable = new HashMap<Ingred,Float>();

    public Cheese() {
    }
    public CheeseType getCheeseType() {
        return cheeseType;
    }
    public void setCheeseType(CheeseType cheeseType) {
        this.cheeseType = cheeseType;
    }
    public Map<Ingred, Float> getCalorieTable() {
        return calorieTable;
    }
    public void setCalorieTable(Map<Ingred, Float> calorieTable) {
        this.calorieTable = calorieTable;
    }       
}
    package com.bean;

    public enum Ingred {
        protein,vitamin,fat
    }
得到答案了吗

公共字符串toString() { 返回字符串.format(getId()+“”+getDescription()+“”+getWeight()+“”+getPrice()+“”+getManufacturingDate()+“”+getUseBeforeMonths()+“”+getExpiryDate()+“”+calorieTable+“”+cheeseType); }得到了答案

公共字符串toString() { 返回字符串.format(getId()+“”+getDescription()+“”+getWeight()+“”+getPrice()+“”+getManufacturingDate()+“”+getUseBeforeMonths()+“”+getExpiryDate()+“”+calorieTable+“”+cheeseType);
}

你的奶酪班在哪里?你的奶酪班在哪里?
    package com.bean;

    public enum Ingred {
        protein,vitamin,fat
    }