为了账号安全,请及时绑定邮箱和手机立即绑定

有大牛知道是哪里错了吗?

public class view {
    private static final String CONTEXT="欢迎来到女神禁区:\n" +
            "下面是女神禁区的功能列表:\n" +
            "[MAIN/M]:主菜单\n" +
            "[QUERY/Q]:查看全部女神的信息\n" +
            "[GET/G]:查看某位女神的详细信息\n" +
            "[ADD/A]:添加女神信息\n" +
            "[UPDATE/U]:更新女神信息\n" +
            "[DELETE/D]:删除女神信息\n" +
            "[SEARCH/S]:查询女神信息(根据姓名、手机号来查询)\n" +
            "[EXIT/E]:退出女神禁区\n" +
            "[BREAK/B]:退出当前功能,返回主菜单";

    private static final String OPERATION_MAIN="MAIN";
    private static final String OPERATION_QUERY="QUERY";
    private static final String OPERATION_GET="GET";
    private static final String OPERATION_ADD="ADD";
    private static final String OPERATION_UPDATE="UPDATE";
    private static final String OPERATION_DELETE="DELETE";
    private static final String OPERATION_SEARCH="SEARCH";
    private static final String OPERATION_EXIT="EXIT";
    private static final String OPERATION_BREAK="BREAK";

    public static void main(String[] args) {
        System.out.println(CONTEXT);
        Scanner scan = new Scanner(System.in);
        Goddess g = new Goddess();
        ActionGoddess ag = new ActionGoddess();
        String prenious = null;
        int step = 1;
        while(scan.hasNext()){
            String in=scan.next().toString();
            if(OPERATION_EXIT.equals(in.toUpperCase())
                    ||OPERATION_EXIT.substring(0, 1).equals(in.toUpperCase())){
                System.out.println("您已成功退出女神禁区。");
                break;
            }else if(OPERATION_ADD.equals(in.toUpperCase())
                    ||OPERATION_ADD.substring(0, 1).equals(in.toUpperCase())
                    ||OPERATION_ADD.equals(prenious)){
                prenious = OPERATION_ADD;
                if(step == 1){
                    System.out.println("请输入女神的姓名:");
                }else if(step == 2){
                    g.setUser_name(in);
                    System.out.println("请输入女神的年龄:");
                }else if(step == 3){
                    g.setAge(Integer.valueOf(in));
                    System.out.println("请输入女神的生日:(例如:yyyy-MM--dd)");
                }else if(step==4){
                    SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
                    try {
                        Date data = sdf.parse(in);
                        g.setBirthday(data);
                        System.out.println("请输入女神的邮箱:");
                    } catch (ParseException e) {
                        e.printStackTrace();
                        step = 3;
                    }
                }else if(step == 5){
                    g.setEmail(in);
                    System.out.println("请输入女神的电话号码:");
                }else if (step==6){
                    g.setMobile(in);
                    try {
                        ag.addGoddess(g);
                        System.out.println("新增女神成功");
                    } catch (Exception e) {
                        e.printStackTrace();
                        System.out.println("新增女神失败");
                    }
                }
                if (prenious.equals(OPERATION_ADD))
                    step++;
            }
        }
    }
}
public class ActionGoddess {
    GoddessDao dao = new GoddessDao();

    public void addGoddess(Goddess g) throws Exception{
        dao.addGod(g);
    }

    public void delG(String name) throws Exception{
        dao.delGoddess(name);
    }

    public void updateG(Goddess goddess) throws Exception{
        dao.updateGoddess(goddess);
    }

    public List<Goddess> query(List<Map<String,Object>> params) throws Exception{
        List<Goddess> goddesses = dao.queryByParams(params);
        return goddesses;
    }

    //查询全部女神
    public List<Goddess> query() throws Exception{
        List<Goddess> gs = dao.query();
        return gs;
    }
}
public class GoddessDao {
    public void addGoddess(Goddess g) throws Exception{
        Connection conn = DBHelper.getConn();
        String sql = ""+
                "insert into imooc_goddess" +
                "(user_name,sex,age,birthday,email,mobile," +
                "create_user,create_date,update_user,update_date,isdel)" +
                "values(" +
                "?,?,?,?,?,?,?,current_date(),?,current_date(),?)";

        PreparedStatement ptmt = conn.prepareStatement(sql);
        ptmt.setString(1, g.getUser_name());
        ptmt.setInt(2, g.getSex());
        ptmt.setInt(3, g.getAge());
        ptmt.setDate(4, new Date(g.getBirthday().getTime()));
        ptmt.setString(5, g.getEmail());
        ptmt.setString(6, g.getMobile());
        ptmt.setString(7, g.getCreate_user());
        ptmt.setString(8, g.getUpdate_user());
        ptmt.setInt(9, g.getIsdel());
        ptmt.execute();
    }
    }

为什么我这里添加女神的时候老是报错?

正在回答

2 回答

GoddessAction.java中修改add函数

public void add(Goddess goddess) throws Exception{
GoddessDao dao=new GoddessDao();
goddess.setSex(1);
goddess.setCreate_user("ADMIN");
goddess.setUpdate_user("ADMIN");
goddess.setIsdel(0);
dao.addGoddess(goddess);
}

2 回复 有任何疑惑可以回复我~
#1

moummm 提问者

非常感谢!
2017-08-26 回复 有任何疑惑可以回复我~

你逗没创坚Goddess对象

0 回复 有任何疑惑可以回复我~

举报

0/150
提交
取消

有大牛知道是哪里错了吗?

我要回答 关注问题
意见反馈 帮助中心 APP下载
官方微信