我这段代码都是写在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]
<%=rs.getString("CONTACTINFOID")%>
<%=rs.getString("CONTACTMAN")%>
<%=rs.getString("DEPARTMENT")%>
<%=rs.getString("MOBILEPHONE")%>
<%=rs.getString("PHONE")%>
[/color] <% }
}
catch (ClassNotFoundException cnfex) {
cnfex.printStackTrace();
}
catch (SQLException sqlex) {
sqlex.printStackTrace();
} catch (Exception e) {
// TODO 自动生成 catch 块
e.printStackTrace();
}
%>