JDBC 中利用存储过程插入数据怎么参数传不进来?(有没有人会的,帮帮忙,困扰了好几天了。谢谢!
public static void main(String[] args){ReplyEmp emp=new ReplyEmp();
emp.setInviationid(1);
emp.setFloor(1);
emp.setNickname("张三");
emp.setTonickname("李四");
emp.setTime(null);
emp.setDate(null);
emp.setContent("说得好!");
emp.setTohost(true);
ReplyDaoImpl impl=new ReplyDaoImpl(dbc.getConnection());
try {
System.out.println(impl.doCreateReply(emp));
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
@Override
public Boolean doCreateReply(ReplyEmp reply) throws Exception {
String sql= "DROP PROCEDURE IF EXISTS reply_insert;"+ //存在储存过程就删除
"DELIMITER $$ "+ //重置自定义的sql语句结束标记
"CREATE PROCEDURE reply_insert(IN r_inviationid int," +
"IN r_floor int,IN r_nickname varchar(45),IN r_tonickname varchar(45)," +
"IN r_time time,IN r_date date,IN r_content varchar(45),IN r_tohost tinyint(4)) "+
"BEGIN "+
"INSERT INTO reply (`inviationid`,`floor`,`nickname`,`tonickname`,`time`," +
"`date`,`content`,`tohost`) " +
"VALUES (r_inviationid,r_floor,r_nickname,r_tonickname," +
"r_time,r_date,r_content,r_tohost);"+
"END $$ "+
"DELIMITER ;"; //设置回默认的sql语句结束标记
this.cstmt=this.conn.prepareCall("{call reply_insert(?,?,?,?,?,?,?,?)}");
this.cstmt=this.conn.prepareCall("{call reply_insert()}");
this.cstmt.setInt(1, reply.getInviationid());
this.cstmt.setInt(2, reply.getFloor());
this.cstmt.setString(3, reply.getNickname());
this.cstmt.setString(4, reply.getTonickname());
this.cstmt.setTime(5, reply.getTime());
this.cstmt.setDate(6, reply.getDate());
this.cstmt.setString(7, reply.getContent());
this.cstmt.setBoolean(8, reply.getTohost()); //1表示true,0表示false
if(this.cstmt.executeUpdate()>0){
return true; //插入成功
}
return false; //插入失败
}
报这样的错误:com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException:Incorrect number of arguments for PROCEDURE forum.reply_insert; expected 0, got 8
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
at java.lang.reflect.Constructor.newInstance(Constructor.java:408)
at com.mysql.jdbc.Util.handleNewInstance(Util.java:411)
at com.mysql.jdbc.Util.getInstance(Util.java:386)
at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:1054)
at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:4190)
at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:4122)
at com.mysql.jdbc.MysqlIO.sendCommand(MysqlIO.java:2570)
at com.mysql.jdbc.MysqlIO.sqlQueryDirect(MysqlIO.java:2731)
at com.mysql.jdbc.ConnectionImpl.execSQL(ConnectionImpl.java:2818)
at com.mysql.jdbc.PreparedStatement.executeInternal(PreparedStatement.java:2157)
at com.mysql.jdbc.PreparedStatement.executeUpdate(PreparedStatement.java:2460)
at com.mysql.jdbc.PreparedStatement.executeUpdate(PreparedStatement.java:2377)
at com.mysql.jdbc.PreparedStatement.executeUpdate(PreparedStatement.java:2361)
at com.mysql.jdbc.CallableStatement.executeUpdate(CallableStatement.java:984)
at com.forum.dao.impl.ReplyDaoImpl.doCreateReply(ReplyDaoImpl.java:89)
at com.forum.dao.impl.ReplyDaoImpl.main(ReplyDaoImpl.java:36)