解决如何通过循环来使用数据库的值设置jsp的select标签的option值

 

Select 处的代码:

[html]  view plain  copy
 
  1. <select name="position">  
  2. <span style="white-space:pre">    </span><%  
  3.     <span style="white-space:pre">    </span>while(rs.next()){  
  4.     %>  
  5.     <option value="<%=rs.getString("position")%>"><%=rs.getString("position") %</option>  
  6.     <!-- 循环得到数据库查找rs中的值并赋值到select的option中 -->  
  7. <span style="white-space:pre">    </span><%  
  8.     <span style="white-space:pre">    </span>}  
  9.         rs.close();  
  10.         st.close();  
  11.         conn.close();  
  12.     %>  
  13. </select>  
[html]  view plain  copy
 
  1. 这是与mysql数据库连接得到select的option共有那些选项的代码:  
[html]  view plain  copy
 
  1. <pre name="code" class="html"><%  
  2.     //与数据库建立连接  
  3.     Class.forName("com.mysql.jdbc.Driver");  
  4.     String url = "jdbc:mysql://localhost:3306/test";  
  5.     String sqlName = "root";  
  6.     String sqlPwd = "root";  
  7.     Connection conn = DriverManager.getConnection(url,sqlName,sqlPwd);  
  8.     Statement st = conn.createStatement();  
  9.     String sqlStr = "select * from tb_position";  
  10.     ResultSet rs = st.executeQuery(sqlStr);             //得到的rs结果集  
  11. %>  

from: http://blog.csdn.net/lei196299/article/details/45059325

 

转载于:https://www.cnblogs.com/ec04/p/7967618.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值