java和oracle中奇怪的异常问题
我有下一个代码:
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类型。
I've got the next code:
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;
}
}
When I execute the line with setFecrec(rs.getTimestamp(4)); it throws the exception: java.lang.ArrayIndexOutOfBoundsException: -1
I don't know what to do. The field in the db comes with null, and the field is type DATE in the database.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
该错误告诉我们,传递给构造函数的实际结果集反映了一个仅包含三列的表。如果索引 4 处的条目格式不正确,那么我们会看到不同的异常类型。
我会查看生成此结果集的实际语句。
The error tells us, that the actual result set, that is passed to the constructors reflects a table with only three columns. If the entry at index 4 wasn't properly formatted, then we'd see a different exception type.
I'd look at the actual statement that produces this resultset.
问题是 DATE 字段的数据库格式存在差异。已经确定了。无论如何,谢谢大家。
The problem was a difference of db formats for DATE fields. It's already fixed. Thanks all anyway.