// Inbergong10: 22 2003-11-11 Article credibility: 99%
JDBCFORSQL2000 Display: After installing the driver, copy the three files in the C: / Program Files / Microsoft SQL Server 2000 Driver for JDBC / LIB directory to the C: / Tomcat 4.1 / Common / Lib directory. <% @ page contenttype = "text / html; charset = ISO8859_1"%> <% @ page import = "java.sql. *"%>
new page 1 title> head>
<% string title = new string (); string content = new string (); string url = "JDBC: Microsoft: SQLServer: //187.186.0.54: 1433; databasename = pubs"; // localhost can be replaced Machine name or IP, PUBS is the database name class.forname ("com.microsoft.jdbc.sqlser.sqlserverdriver). NewInStance (); string user =" sa "; // SQL database username string password =" gyb " ; // password Connection conn = DriverManager.getConnection (url, user, password); Statement stmt = conn.createStatement (ResultSet.TYPE_SCROLL_SENSITIVE, ResultSet.CONCUR_UPDATABLE); String SQL = new String (); SQL = "SELECT * FROM sales" ; // Data Sheet Name: SalesResultSet RS = Stmt.executeQuery (SQL); INT J; for (j = 0; rs.next (); j ) {title = rs.getstring ("stor_id"); // STOR_ID is Field name content = rs.getstring ("ORD_NUM"); // ORD_NUM is the field name%> <% = j 1%>. Title: <% = title%>
content: <% = content%> < P>
<%} if (j == 0) {%> There is currently no content you record! ! !
<%}%> body>
html>
2 Chinese data display <% @ page contenttype = "text / html; charset = GB2312"%> <% @ page import = "java.sql. *"%>
new page 1 title> head> <% string title = new string (); string content = new string (); String URL = "JDBC: Microsoft: SQLServer: //187.186.0.54: 1433; DatabaseName = E_BIZBID_NETSTARS_COM_CN"; // localhost can be replaced with machine name or IP, PUBS is the database name class.forname ("com.microsoft.jdbc.sqlserver .Sqlserverdriver "). Newinstance (); String user =" sa "; // SQL database username string password =" gyb "; // password connection conn = drivermanager.getConnection (URL, user, password); statement stmt = conn.createStatement (ResultSet.TYPE_SCROLL_SENSITIVE, ResultSet.CONCUR_UPDATABLE); String SQL = new String (); SQL = "SELECT * FROM reged_user"; // table name: salesResultSet rs = stmt.executeQuery (SQL); int j; for (j = 0; rs.next (); j ) {title = rs.getstring ("easy_name"); content = rs.getstring ("org_name");%> <% = j 1%>. Abbrevite: < % = Title%>
company full name: <% = content%>
<%} if (j == 0) {%> There is currently no content you record! ! !
<%}%> body> html>