Select 处的代码:
- <select name="position">
- <span style="white-space:pre"> </span><%
- <span style="white-space:pre"> </span>while(rs.next()){
- %>
- <option value="<%=rs.getString("position")%>"><%=rs.getString("position") %> </option>
- <!-- 循环得到数据库查找rs中的值并赋值到select的option中 -->
- <span style="white-space:pre"> </span><%
- <span style="white-space:pre"> </span>}
- rs.close();
- st.close();
- conn.close();
- %>
- </select>
- 这是与mysql数据库连接得到select的option共有那些选项的代码:
- <pre name="code" class="html"><%
- //与数据库建立连接
- Class.forName("com.mysql.jdbc.Driver");
- String url = "jdbc:mysql://localhost:3306/test";
- String sqlName = "root";
- String sqlPwd = "root";
- Connection conn = DriverManager.getConnection(url,sqlName,sqlPwd);
- Statement st = conn.createStatement();
- String sqlStr = "select * from tb_position";
- ResultSet rs = st.executeQuery(sqlStr); //得到的rs结果集
- %>
from: http://blog.csdn.net/lei196299/article/details/45059325