解决JSP中的无效列类型

时间:2016-03-25 09:33:05

标签: java oracle jsp

我有以下数据库:

1)Emp_master

EMPID Number primary key
FNAME Varchar2
LNAME Varchar2
GENDER Varchar2
DOB Date
DEPTID Number

2)Emp_Leave

LEAVETYPE   Varchar2(30)
DATEFROM    Date
DATETO  Date
NO_OF_DAYS  Number
STATUS  Varchar2(10)
ENO Number(5)

现在当我在JSP中执行以下代码时,我收到错误:

  

列类型无效:没有为class.oracle.jdbc.driver.T4CNumberAccessor实现getDate

这是代码:

eno=Integer.parseInt(request.getParameter("Eno"));
Class.forName("oracle.jdbc.driver.OracleDriver");
Connection con=DriverManager.getConnection("jdbc:oracle:thin:@localhost:1521:XE", "HR","HR");

Statement st=con.createStatement();

        String qry1="select leavetype datefrom,dateto,no_of_days,status from emp_leave where eno="+eno;
        ResultSet rs1=st.executeQuery(qry1);
        rs1.next();
        type=rs1.getString(1);
        dt_from=rs1.getDate(2);
        dt_to=rs1.getDate(3);
        days=rs1.getInt(4);
        status=rs1.getString(5);


        String qry2="select fname,lname from emp_master where empid="+eno;
        ResultSet rs2=st.executeQuery(qry2);
        rs2.next();
        fname=rs2.getString(2);
        lname=rs2.getString(3);

我似乎无法弄清楚为什么会抛出错误。我已将dt_fromdt_to声明为Date数据类型变量。

1 个答案:

答案 0 :(得分:0)

只需将查询与getter进行比较:
select leavetype datefrom,dateto,no_of_days,status from emp_leave where ...

 type=rs1.getString(1);  // gets: leavetype datefrom 
 dt_from=rs1.getDate(2); // gets: dateto
 dt_to=rs1.getDate(3);  // gets: no_of_days (of type: Number ) <= this throws the error !!!
 days=rs1.getInt(4);  // gets: status (of type: Varchar)
 status=rs1.getString(5); // gest: ???

leavetypedatefrom之间的SELECT statament中很可能缺少逗号。

在SQL中,SELECT clasue中的以下表达式:

SELECT somename someanothername FROM .....

是:

   SELECT somename AS someanothername FROM .....

此SELECT仅检索一个名为somename的列,并将其重命名为someanothername