时间: 2021-07-31 作者:daque
三、jsp贯穿db2数据库 testdb2.jsp如次: <%@ page contenttype="text/html;charset=utf8"%> <%@ page import="java.sql.*"%> <html> <body> <%class.forname("com.ibm.db2.jdbc.app.db2driver ").newinstance(); string url="jdbc:db2://localhost:5000/sample"; //sample为你的数据库名 string user="admin"; string password=""; connection conn= drivermanager.getconnection(url,user,password); statement stmt=conn.createstatement(resultset.type_scroll_sensitive,resultset.concur_updatable); string sql="select * from test"; resultset rs=stmt.executequery(sql); while(rs.next()) {%> 您的第一个字段实质为:<%=rs.getstring(1)%> 您的第二个字段实质为:<%=rs.getstring(2)%> <%}%> <%out.print("数据库操纵胜利,祝贺你");%> <%rs.close(); stmt.close(); conn.close(); %> </body> </html>