我正在尝试从MS Access数据库中获取一个字段并将其设置为文本框值。
我正在尝试使用以下代码:
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix= "sql" uri="http://java.sun.com/jsp/jstl/sql" %>
<sql:setDataSource
var = "bookdB"
scope = "session"
driver = "sun.jdbc.odbc.JdbcOdbcDriver"
url = "jdbc:odbc:bookdB"
/>
<sql:query dataSource="${bookdB}" var="result">
SELECT * from Company;
</sql:query>
<!-- Create third layer -->
<form method="post" action="edit_company22.jsp">
<table style="position:absolute; left:387px; top:105px; height:124px; width:810px" border="0" bordercolor="#FFFFFF" style="background-color:#FFFFFF" width="85%" cellpadding="5" cellspacing="5" rules=groups>
<div style="position:absolute; left:380px; top:70px; width:850px; height:570px; border:1px solid black">
<tr>
<th>Phone:</th>
<td><input type="input" name="data1" value=""></td>
非常感谢任何帮助。谢谢。
答案 0 :(得分:1)
你正在寻找这样的东西:
<c:forEach var="row" items="${result.rows}">
<tr>
<th>Phone:</th>
<td><input type="input" name="data1" value="${row.phonenumber}" /></td>
</tr>
..... //the rest of your form
</c:forEach>
顺便说一句,您的SQL(“SELECT * from Company;”)可能不是您真正想要的,因为您可能只希望每个表单只有一个公司,而不是整个表。
另请参阅JSTL SQL教程:http://docs.oracle.com/javaee/5/tutorial/doc/bnald.html