Java and SQLServer2000 connection (final version)!

zhaozj2021-02-08  245

It is said that Microsoft's JDBC driver does not support "repeated query", so use net.sourceforge.jtds.jdbc.driver (http://jtds.sourceforge.net/) to install SQLServer2000 on Win2003 Server, you must install patch SP3

Note: Class.Forname method in Java must be a captured error, put it in try {} catch (classnotfountException {}) {} will not have error in another class_path must join JTDS-xxx.jar's complete The path name is as: ./; ...; d: /j2sdk1.4.2_01/jre/lib/ext/jtds-0.5.1.jar;

/ * * Author: liufei * HomePage: histp://www.liufei.com * Copyright 2003 Henan SUNCER SOFTWARE Inc. All rights reserved. * / Import java.sql. *; Import java.util. *; Class sql {public Static void main (string [] args) {try {string query = "SELECT * from Orders"; string url = "JDBC: JTDS: SQLServer: //135.0.0.2: 1433 / Northwind; user = sa; password = webserver ; Class.forName ( "net.sourceforge.jtds.jdbc.Driver"); Connection conn = DriverManager.getConnection (URL); Statement stmt = conn.createStatement (ResultSet.TYPE_SCROLL_SENSITIVE, ResultSet.CONCUR_UPDATABLE); ResultSet rs = stmt.executeQuery (query); int i = 0; for (i = 0; i <10; i ) {r.next (); system.out.println (rs.getstring (1));} // SQLServer2k comes with In the case of Database Northwind, there are more than 10 tables, may be recorded hundred records, so only 10! } Catch (exception e) {system.out.println (E.getMessage ());}}}

Use JSP connection:

JTDs.jar must be placed in a web-inf / lib directory

The Test.jsp content is as follows:

<% @ Page ContentType = "Text / HTML; Charset = GB2312"%> <% @ page import = "java.sql. *"%> <% class.forname ("Net.Sourceforge.jtds .jdbc.driver "). NewInstance (); string url =" JDBC: JTDS: SQLServer: //135.0.0.2: 1433 / Northwind; user = sa; password = webserver

转载请注明原文地址:https://www.9cbs.com/read-3122.html

New Post(0)