JSP select标签数据库绑定数据

来源:百度知道 编辑:UC知道 时间:2024/05/31 08:45:30
<%! private static final String SELECT_ALLIANCE_STMT="select allianceName from Alliance ";
ResultSet results = null;
DataSource ds = null;
Connection connection = null;
PreparedStatement stmt = null;
int num_of_rows = 0;
ArrayList arraylist=null; Iterator iterator=null; %>
<%! public void jspInit(){

try{
Context context = new InitialContext();
if ( context == null ) {
throw new RuntimeException("JNDI Context could not be found.");
}
ds = (DataSource)context.lookup("java:comp/env/jdbc/leagueDB");
if ( ds == null ) {
throw new RuntimeException("DataSource could not be found.");
}
connection = ds.getConnection();
stmt = connection.prepareStatement(SELECT_ALLIANCE_STMT);

<% while(rs.next()) {%>
<option value="<%=results.getString("allianceName")%>"><%=results.getString("allianceName")%></option>
<%}%>
---------------------------
或者将arraylist做个循环

楼上2位水平比较高
我也是只会一点java
jsp不懂
帮不上忙!

<option value="<%=iterator%>"><%=iterator%></option>
改为
<option value="<%=iterator.next()%>"><%=iterator.next()%></option>

JSP不太懂.
只会点JAVA

俺会一点java,但不懂jsp.