这里我尝试在组合框中显示值,但组合框在输出中显示为空!我的数据库表只有两个字段,名称和资格,具有足够的值。 最佳答案 你的代码 }catch(Exception -6ren">
gpt4 book ai didi

java - 从数据库检索时组合框中没有数据

转载 作者:太空宇宙 更新时间:2023-11-04 13:05:12 24 4
gpt4 key购买 nike

<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>

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

最佳答案

你的代码

 }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 引擎)

关于java - 从数据库检索时组合框中没有数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34533080/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com