1、使用JSP连接要SQL Server 7.0/2000数据库 //testsqlserver.jsp <% ... @ page contentType="text/html; charset="gb2313" %><%@ page import="java.sql.*" %> < html > < body > <% ... Class.forName("com.microsoft.jdbc.sqlserver.SQLServerDriver").newInstance(); String url="jdbc:microsoft:sqlserver://localhost:1433; DatabaseName=newe"; String user="Administrator"; String password="123456"; Connection conn=DriverManager.getConnection(url, user, password); Statement stmt=conn.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE, ResultSet.CONCUR_UPDATABLE); String sql="select * from student"; ResultSet rs=stmt.ExecuteQuery(sql); while(rs.next()){ %> <% ... = rs.getString(1) %> <% ... = rs.getString(2) %> <% ... } %> <% ... rs.close(); stmt.close(); conn.close(); %> </ body > </ html > 2、使用JSP连接DB2 //testdb2.jsp <% ... @ page contentType="text/html;charset=gb2312" %> <% ... @ page import="java.sql.*" %> < html > < body > <% ... Class.forName("com.ibm.db2.jdbc.app.DB2Driver").newInstance(); String url="jdbc:db2://localhost:5000/sample"; String user="admin"; String password="admin"; 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) %> <% ... } %> <% ... rs.close(); stmt.close(); conn.close(); %> </ body > </ html >