下面的代码不知为何会报错,硬是找不出问题,麻烦各位帮忙看看!
多谢提醒,错误信息!
Mon Jul 23 17:36:00 CST 2012 WARN: Invalid value {1} for server variable named {0}, falling back to sane default of {2}.
Exception in thread "main" com.mysql.jdbc.exceptions.jdbc4.MySQLIntegrityConstraintViolationException: Duplicate entry '0' for key 1
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:39)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:27)
at java.lang.reflect.Constructor.newInstance(Constructor.java:513)
at com.mysql.jdbc.Util.handleNewInstance(Util.java:406)
at com.mysql.jdbc.Util.getInstance(Util.java:381)
at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:1015)
at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:956)
at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:3515)
at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:3447)
at com.mysql.jdbc.MysqlIO.sendCommand(MysqlIO.java:1951)
at com.mysql.jdbc.MysqlIO.sqlQueryDirect(MysqlIO.java:2101)
at com.mysql.jdbc.ConnectionImpl.execSQL(ConnectionImpl.java:2554)
at com.mysql.jdbc.PreparedStatement.executeInternal(PreparedStatement.java:1761)
at com.mysql.jdbc.PreparedStatement.executeUpdate(PreparedStatement.java:2046)
at com.mysql.jdbc.PreparedStatement.executeUpdate(PreparedStatement.java:1964)
at com.mysql.jdbc.PreparedStatement.executeUpdate(PreparedStatement.java:1949)
at cn.itcast.jdbc.CRUD.create(CRUD.java:22)
at cn.itcast.jdbc.CRUD.main(CRUD.java:9)
package cn.itcast.jdbc;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.util.Date;
public class CRUD {
public static void main(String[] args) throws Exception{
create("tianjian",new Date(),799.0f);
}
public static void create(String name,Date birthday,float money) throws Exception{
Connection conn=null;
PreparedStatement ps=null;
ResultSet rs=null;
try{
conn=JDBCUtils.getConnection();
String sql="insert into user(name,birthday,money)values(?,?,?)";
ps=conn.prepareStatement(sql);
ps.setString(1, name);
ps.setDate(2, new java.sql.Date(birthday.getTime()));