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

at com.imooc.dao.GoddessDao.addGoddess(GoddessDao.java:25) at com.imooc.action.GoddessAction.main(GoddessAction.java:28)

GodessAction.java文件

package com.imooc.action;


import java.sql.Date;

import java.sql.SQLException;

import java.util.List;



import com.imooc.dao.GoddessDao;

import com.imooc.model.Goddess;


public class GoddessAction {


public static void main(String[] args) throws Exception{

GoddessDao g=new GoddessDao();

Goddess g1=new Goddess();

g1.setUser_name("小夏");

g1.setAge(22);

g1.setSex(1);

g1.setBirthday(new java.util.Date());

g1.setEmail("xiaoxian@imooc.com");

g1.setMobile("18766888866");

g1.setCreate_user("Admin");

g1.setUpdate_user("Admin");

g1.setIsdel(1);

g.addGoddess(g1);

}

}

GoddessDao.java文件

package com.imooc.dao;


import java.sql.Connection;

import java.sql.PreparedStatement;

import java.sql.ResultSet;

import java.sql.SQLException;

import java.sql.Statement;

import java.util.ArrayList;

import java.util.Date;

import java.util.List;


import com.imooc.db.DBUtil;

import com.imooc.model.Goddess;


public class GoddessDao {

 

public void addGoddess(Goddess g) throws Exception{

Connection conn=DBUtil.getConnection();

String sql=""+

"insert into imooc_goddess"+

"(user_name,sex,age,birthday,email,mobile,"+

"create_user,create_date,update_user,update_date,isdel)"+

"valurs(" +

"?,?,?,?,?,?,?,?,?,?,?)";

PreparedStatement ptmt=conn.prepareStatement(sql);

ptmt.setString(1, g.getUser_name());

ptmt.setInt(2, g.getSex());

ptmt.setInt(3, g.getAge());

    ptmt.setDate(4, (java.sql.Date) 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();

ptmt.execute();

}

public void updateGoddess(){

}

public void delGoddess(){

}

public List<Goddess> query() throws SQLException{

Connection conn=DBUtil.getConnection();

Statement stmt=conn.createStatement();

ResultSet rs=stmt.executeQuery("select user_name,age from imooc_goddess");

List<Goddess> gs=new ArrayList<Goddess>();

Goddess g=null;

while(rs.next()){

g=new Goddess();

g.setUser_name(rs.getString("user_name"));

g.setAge(rs.getInt("age"));

gs.add(g);

}

return gs;

}

public Goddess get(){

return null;

}

}


正在回答

1 回答

你的DAO文件里,String sql语句的中,有11个占位符:“?”。但是后续的ptmt只赋予了9个值。


解决方法:将第8、10个“?” 替换为:

current_date()


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

举报

0/150
提交
取消

at com.imooc.dao.GoddessDao.addGoddess(GoddessDao.java:25) at com.imooc.action.GoddessAction.main(GoddessAction.java:28)

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