我这段代码都是写在jsp也上面的,但是现在要求要把数据库连接等逻辑代码都放Bean里面,那我现在的表格里面怎么放数据呢,请教大家,谢谢。
<%
Connection connection = null;
PreparedStatement pstmt = null;
ResultSet rs = null;
try {
Class.forName("oracle.jdbc.driver.OracleDriver").newInstance();
String dbUrl = "jdbc:oracle:thin:@10.0.0.129:1521:cdfy";
String user = "prstest";
String password = "prstest";
String sql="select * from wangsonghuai";
connection=DriverManager.getConnection(dbUrl,user,password);
pstmt = (PreparedStatement) connection.prepareStatement(sql);
rs=pstmt.executeQuery();
while(rs.next()){%>
[color=red]
}
catch (ClassNotFoundException cnfex) {
cnfex.printStackTrace();
}
catch (SQLException sqlex) {
sqlex.printStackTrace();
} catch (Exception e) {
// TODO 自动生成 catch 块
e.printStackTrace();
}
%>
建一个对像。把从数据库里读的值放到对像里,表格要显示时,从该对像里拿值
数据的遍历就可以用jstl的 标签来遍历嘛
把数据查询出来放到request里就可以取数据了