<%
exec="select * from 表"
set rs=server.createobject("adodb.recordset")
rs.open exec,conn,1,1
%>
请问楼主用的是什么数据库啊?不知道说的什么意思,你会JSTL语言吗?我先简单的说一下我的做法: 1.链接数据库,我连接的是Oracle数据库2.比如说我要显示的是一个Users的信息:User.jsppackage com.howen.ldf.daoimport java.io.Serializablepublic class Users implements Serializable {private int userId
private String userName
private String userPwd
private String regDate
public int getUserId() {
return userId
}
public void setUserId(int userId) {
this.userId = userId
}
public String getUserName() {
return userName
}
public void setUserName(String userName) {
this.userName = userName
}
public String getUserPwd() {
return userPwd
}
public void setUserPwd(String userPwd) {
this.userPwd = userPwd
}
public String getRegDate() {
return regDate
}
public void setRegDate(String regDate) {
this.regDate = regDate
}
}
3.建立dao:UsersDaoImpl.jsppackage com.howen.ldf.daoimport java.sql.Connection
import java.sql.PreparedStatement
import java.sql.ResultSet
import java.sql.SQLException
import java.util.ArrayListpublic class UsersDaoImpl implements IUsersDao { public ArrayList<Users>query() throws SQLException {
// TODO Auto-generated method stub
Connection con=DBConnection.getConnection()
String sql="select user_id,userName,passWord,to_char(reg_date) from t_users"
PreparedStatement ps=DBConnection.getPro(con, sql)
ResultSet rs=ps.executeQuery()
ArrayList<Users>users=new ArrayList<Users>()
while(rs.next()){
Users user=new Users()
user.setUserId(rs.getInt("user_id"))
user.setUserName(rs.getString("userName"))
user.setUserPwd(rs.getString("passWord"))
user.setRegDate(rs.getString(4))
users.add(user)
}
return users
} }
4.建立业务层Bo:UsersServiceImpl.jsppackage com.howen.ldf.serviceimport java.sql.SQLException
import java.util.Listimport com.howen.ldf.dao.IUsersDao
import com.howen.ldf.dao.Users
import com.howen.ldf.dao.UsersDaoImplpublic class UsersServiceImpl implements IUsersService {
private IUsersDao dao
public UsersServiceImpl(){
dao=new UsersDaoImpl()
}
public List<Users>queryAll() throws SQLException {
return dao.query()
}
}
5.建立Servletwen文件(doGet()里的源代码):Query.javaIUsersService ius=new UsersServiceImpl()
List<Users>users = null
try {
users = ius.queryAll()
HttpSession session=request.getSession()
session.setAttribute("a", users)
response.sendRedirect("showUsers.jsp")
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace()
}6.在Jsp里用JSTL语言实现:showUser.jsp<table width=500>
<tr>
<td>user_id</td>
<td>userName</td>
<td>userPassword</td>
<td>regDate</td>
</tr>
<c:forEach var="user" items="${a}">
<tr>
<td><c:out value="${user.userId}"/></td>
<td><c:out value="${user.userName}"/></td>
<td><c:out value="${user.userPwd}"/></td>
<td><c:out value="${user.regDate}"/></td>
</tr>
</c:forEach>
</table>好了,现在在你的浏览器输入:根目录:Query即可实现你想要的结果了,由于篇幅的限制,只能写这么多了,这只是一个过程,有什么不明白的欢迎接着问,大家一起探讨!
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)