//jdbc连接Oracle 查询主题表的信息:主题编号 主题名称
//两个字符串
String uRL="jdbc:oracle:thin:@localhost:1521:orcl"
String CNAME="oracle.jdbc.driver.OracleDriver"
//加载驱动
Class.forName(CNAME);
//创建连接
Connection con=DriverManager.getConnection(URL,"scott","tiger");
//定义sql语句
String sql="select * from topic279 order by tid";
//获取执行对象
PerparedStatement ps=con.preparStatement(sql);
//获取结果集
ReslutSet rs=ps.executeQuery();
//遍历结果集
while(rs.next()){
%>
<option value='<%=rs.getInt(1)%>'><%=rs.getString(2) %>></option>
<%
}
//关闭资源3个
if(con!=null&&!con.isClosed()){
con.close();
}
if(ps!=null){
ps.close();
}
if(rs!=null){
rs.close();
}
%>
//遍历结果集
while(rs.next()){
//地址栏传参: ?键=值&键=值
%>
<li><a href="read.jsp?nid=<%=rs.getInt(1) %>>"><%=rs.getString(2) %></a> <span> 作者:<%=rs.getString(3) %>>    
<a href='update.jsp?nid=<%=rs.getInt(1) %>>'>修改</a>     
<a href='dodelete.jsp?nid=<%=rs.getInt(1) %>' onclick='return clickdel()'>删除</a> </span>
</li>
<%
}
//关闭资源3个
if(con!=null&&!con.isClosed()){
con.close();
}
if(ps!=null){
ps.close();
}
if(rs!=null){
rs.close();
}
//遍历结果集
while(rs.next()){
//判断如果是当前这一条新闻的主题编号的话就让其选中
if(rs.getInt(1)==tid){
out.print("<option selected='selected' value='"+rs.getInt(1)+"'>"+rs.getString(2)+"</option>");
}
else{//否则 不选中 为了能够修改
out.print("<option value='"+rs.getInt(1)+"'>"+rs.getString(2)+"</option>");
}
//关闭资源3个
if(con!=null&&!con.isClosed()){
con.close();
}
if(ps!=null){
ps.close();
}
if(rs!=null){
rs.close();
}
%>
<!--如何让下拉框默认选中-->
//<option value="11" selected="selected">嘿嘿嘿</option>
</select>
<!--隐藏域传值 会随着表单的提交而提交 后期根据name值取value值-->
<input name="nid" type="hidden" value="<%=nid %>>">
以上过程会产生以下流程
这些就是流程结果,需要注意的是方法的使用