java和oracle中的奇怪异常问题

时间:2011-05-25 15:50:14

标签: java oracle exception timestamp

我有下一个代码:

package model.composite;

import java.util.Date;
import Nwt.Registro;
import java.sql.ResultSet;

import annotations.DateFormatAnnotation;

/**
 * Clase que declara el tipo de registro para manejar la información del turno de servicio.
 * @author xx357
 *
 */
public class RegistroTur extends Registro{
    private String  codrec;
    private String  locrec;
    private String  turdsr;
    @DateFormatAnnotation(patron = "dd/MM/yyyy HH:mm")
    private Date    fecrec;
    private String  estrec;
    private String  estemi;
    @DateFormatAnnotation(patron = "dd/MM/yyyy HH:mm")
    private Date    fecemi;
    private String  estcre;
    private int     priwls;
    private String  delope;
    @DateFormatAnnotation(patron = "dd/MM/yyyy HH:mm")
    private Date    fecope;
    private String  nomage;
    @DateFormatAnnotation(patron = "dd/MM/yyyy HH:mm")
    private Date    faxpet;
    @DateFormatAnnotation(patron = "dd/MM/yyyy HH:mm")
    private Date    Faxcnx;
    @DateFormatAnnotation(patron = "dd/MM/yyyy HH:mm")
    private Date    Faxprs;
    @DateFormatAnnotation(patron = "dd/MM/yyyy HH:mm")
    private Date    Faxcnp;
    private String  usrcre;
    @DateFormatAnnotation(patron = "dd/MM/yyyy HH:mm")
    private Date    datcre;
    private String  usrmod;
    @DateFormatAnnotation(patron = "dd/MM/yyyy HH:mm")
    private Date    datmod;
    @DateFormatAnnotation(patron = "dd/MM/yyyy HH:mm")
    private Date    fecbaj;
    private String  usrbaj;
    private String  tarext;
    private String  codaut;
    private String  carmat;

    public RegistroTur(){
    }

    public RegistroTur(ResultSet rs) throws Exception{
        setCodrec(rs.getString(1));
        setLocrec(rs.getString(2));
        setTurdsr(rs.getString(3));
        setFecrec(rs.getTimestamp(4));
        setEstrec(rs.getString(5));

        setEstemi(rs.getString(6));
        setFecemi(rs.getTimestamp(7));
        setEstcre(rs.getString(8));
        setPriwls(rs.getInt(9));
        setDelope(rs.getString(10));

        setFecope(rs.getTimestamp(11));
        setNomage(rs.getString(12));
        setFaxpet(rs.getTimestamp(13));
        setFaxcnx(rs.getTimestamp(14));
        setFaxprs(rs.getTimestamp(15));

        setFaxcnp(rs.getTimestamp(16));
        setUsrcre(rs.getString(17));
        setDatcre(rs.getTimestamp(18));
        setUsrmod(rs.getString(19));
        setDatmod(rs.getTimestamp(20));

        setFecbaj(rs.getTimestamp(21));
        setUsrbaj(rs.getString(22));
        setTarext(rs.getString(23));
        setCodaut(rs.getString(24));
        setCarmat(rs.getString(25));
    }

    public void setCodrec(String codrec) {
        this.codrec = codrec;
    }

    public String getCodrec() {
        return codrec;
    }

    public void setLocrec(String locrec) {
        this.locrec = locrec;
    }

    public String getLocrec() {
        return locrec;
    }

    public void setTurdsr(String turdsr) {
        this.turdsr = turdsr;
    }

    public String getTurdsr() {
        return turdsr;
    }

    public void setFecrec(Date fecrec) {
        this.fecrec = fecrec;
    }

    public Date getFecrec() {
        return fecrec;
    }

    public void setEstrec(String estrec) {
        this.estrec = estrec;
    }

    public String getEstrec() {
        return estrec;
    }

    public void setEstemi(String estemi) {
        this.estemi = estemi;
    }

    public String getEstemi() {
        return estemi;
    }

    public void setFecemi(Date fecemi) {
        this.fecemi = fecemi;
    }

    public Date getFecemi() {
        return fecemi;
    }

    public void setEstcre(String estcre) {
        this.estcre = estcre;
    }

    public String getEstcre() {
        return estcre;
    }

    public void setPriwls(int priwls) {
        this.priwls = priwls;
    }

    public int getPriwls() {
        return priwls;
    }

    public void setDelope(String delope) {
        this.delope = delope;
    }

    public String getDelope() {
        return delope;
    }

    public void setFecope(Date fecope) {
        this.fecope = fecope;
    }

    public Date getFecope() {
        return fecope;
    }

    public void setNomage(String nomage) {
        this.nomage = nomage;
    }

    public String getNomage() {
        return nomage;
    }

    public void setFaxpet(Date faxpet) {
        this.faxpet = faxpet;
    }

    public Date getFaxpet() {
        return faxpet;
    }

    public void setFaxcnx(Date faxcnx) {
        Faxcnx = faxcnx;
    }

    public Date getFaxcnx() {
        return Faxcnx;
    }

    public void setFaxprs(Date faxprs) {
        Faxprs = faxprs;
    }

    public Date getFaxprs() {
        return Faxprs;
    }

    public void setFaxcnp(Date faxcnp) {
        Faxcnp = faxcnp;
    }

    public Date getFaxcnp() {
        return Faxcnp;
    }

    public void setUsrcre(String usrcre) {
        this.usrcre = usrcre;
    }

    public String getUsrcre() {
        return usrcre;
    }

    public void setDatcre(Date datcre) {
        this.datcre = datcre;
    }

    public Date getDatcre() {
        return datcre;
    }

    public void setUsrmod(String usrmod) {
        this.usrmod = usrmod;
    }

    public String getUsrmod() {
        return usrmod;
    }

    public void setDatmod(Date datmod) {
        this.datmod = datmod;
    }

    public Date getDatmod() {
        return datmod;
    }

    public void setFecbaj(Date fecbaj) {
        this.fecbaj = fecbaj;
    }

    public Date getFecbaj() {
        return fecbaj;
    }

    public void setUsrbaj(String usrbaj) {
        this.usrbaj = usrbaj;
    }

    public String getUsrbaj() {
        return usrbaj;
    }

    public void setTarext(String tarext) {
        this.tarext = tarext;
    }

    public String getTarext() {
        return tarext;
    }

    public void setCodaut(String codaut) {
        this.codaut = codaut;
    }

    public String getCodaut() {
        return codaut;
    }

    public void setCarmat(String carmat) {
        this.carmat = carmat;
    }

    public String getCarmat() {
        return carmat;
    }
}

当我用setFecrec(rs.getTimestamp(4))执行该行时;它抛出异常:java.lang.ArrayIndexOutOfBoundsException:-1

我不知道该怎么办。 db中的字段为null,字段在数据库中为DATE类型。

2 个答案:

答案 0 :(得分:2)

错误告诉我们,传递给构造函数的实际结果集反映了一个只有三列的表。如果索引4处的条目格式不正确,那么我们会看到不同的异常类型。

我会查看产生此结果集的实际语句。

答案 1 :(得分:0)

问题是DATE字段的db格式不同。它已经修好了。无论如何,谢谢大家。