【问题标题】:No data in combobox while retrieving from database从数据库中检索时组合框中没有数据
【发布时间】:2016-04-04 15:18:36
【问题描述】:
<select name="qualification">
   <%
     Connection con=null;
     Statement st=null;
     ResultSet res;
     try{
       Class.forName("oracle.jdbc.driver.OracleDriver");
       con=DriverManager.getConnection("jdbc:oracle:thin:@127.0.0.1:1521:XE","system","123");
       st=con.createStatement();
       res=st.executeQuery("select qualification from course");
       while(res.next()){
         String qualification = res.getString("qualification");
  %>
      <option value="<%=qualification%>"><%=qualification%></option>
  <%
      }
    }catch(Exception e)
    {    out.print(e);
    }
 %>

</select>

这里我试图在组合框中显示值,但组合框在输出中显示为空! 我的 db 表只有两个字段,名称和具有足够值的资格。

【问题讨论】:

  • 服务器日志中是否有错误信息(tomcat之类的?)
  • 没有错误!代码工作正常..但组合框还空。表格有足够的值可以显示。
  • 您是否检查了呈现的 html 代码(查看源代码、检查元素)?
  • 哦..它显示 classNotFoundException 虽然一切都设置正确!
  • 不能。你不能与classNotFoundException 争论。找不到什么类(我的猜测:Oracle 驱动程序)

标签: java jsp jdbc combobox


【解决方案1】:

你的代码

 }catch(Exception e)
{    out.print(e);
}

将错误输出到您难以找到的 html 中。考虑将完整的堆栈跟踪记录到服务器日志中

 }catch(Exception e) {    
   e.printStackTrace ();
   out.print(e);
 }

正如您在评论中提到的,您看到一个找不到 Oracle 驱动程序的类 - 确保将 ojdbc6.jar(或 ojdbc7.jar)添加到您的 WEB-INF/lib 或您的 tomcat/lib 文件夹(或类似文件夹中,具体取决于在您的 servlet 引擎上)

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2014-07-14
    • 1970-01-01
    • 1970-01-01
    • 2016-03-29
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多