ps.setObject(2,"tmd",Types.LONGVARBINARY);//字段2的类型是IMAGE
        //ps.setNull(2,Types.LONGVARBINARY);//如果将上句换成此句,则程序通过
替换后当然会通过了,你给它赋空那
//字段2的类型是IMAGE
那你
ps.setObject(2,"tmd",Types.LONGVARBINARY);明显给的不是对应的类型阿,给的是一个字符串“tmd”阿,变量类型不对,当然不行了

解决方案 »

  1.   

    我说替换后可以通过的意思是指系统认为
      ps.setObject(1,"3",Types.INTEGER);//字段1的类型是int
    这句没有错误,按照您的理论,那这句应该是
      ps.setObject(1,new Integer(3),Types.Integer);
    才能通过了?
      J2SDK1.4中对setObject(int parameterIndex,                    Object x)的说明中这样的话:
    Sets the value of the designated parameter using the given object. The second parameter must be of type Object; therefore, the java.lang equivalent objects should be used for built-in types. The JDBC specification specifies a standard mapping from Java Object types to SQL types. The given argument will be converted to the corresponding SQL type before being sent to the database. 而且本程序对MYSQL的操作是正确的。使用的JDBC是mm.mysql-2.0.14。