Use Microsoft JDBC Driver to connect to SQL Server2000 in JSP

zhaozj2021-02-16  62

Originally this problem is the old problem, but I checked the Chinese information on the Internet. It is really ... or I don't know. If there is a problem, I have a problem in the 9CBS Forum, I'm talking about only JSP code Connecting SQL Server, and slightly, you must install Microsoft JDBC driver. I have to read 9CBS forum posts and personally practicate many times, now summarize as follows:

The situation is much better than the imagination: I have been toned for more than an hour, I finally connected to SQL Server2000, very annoyed, huh, huh! 1. Install Microsoft JDBC Driver Do not do the "Next" to complete the installation.

2. Configure the role of environmental variables first:

Java_Home Variable: Used to set the directory Tomcat_Home variable for the Java development package: used to set the directory where the Tomcat server is located

ClassPath Variables: IMPORT Some class libraries in the compiled Java or JSP file (such as java.io. *, java.lang. *, Etc.), you must know when compiling JavaC.exe compiles Java or JSP files, you must know these class libraries. The path. Therefore, the classpath is the search path for setting the Java class library, which typically needs to set the value in the classpath:% java_home% / lib. When you install Microsoft JDBC Driver, also need to add:% JDBC_INSTALL_PATH% / lib / msbase.jar;% JDBC_INSTALL_PATH% / lib / mssqlserver.jar;% JDBC_INSTALL_PATH% / msutil.jar Note:% JDBC_INSTALL_PATH% of installing Microsoft JDBC Driver Directory, for example, set this environment variable JDBC_INSTALL_PATH = "C: / Program Files / Microsoft JDBC Driver"

Path Variable: Used to set up java.exe (executing compiled class), JavaC.exe (compiled Java files), etc., for example, you can type JavaC.exe directly under the DOS console, not Switch to JavaC.exe where JavaC.exe is executed.

3. Key points must remember that after installing the Microsoft JDBC, three JAR files in the LIB directory in the installation directory: msbase.jar, mssqlser.jar, msutil.jar Copy to the Tomcat directory in the common / lib directory, then Must restart Tomcat! The purpose of doing this is that the JSP page does not have a problem with the SQL Server Driver class library in the compilation process.

But I really don't understand:% java_home% / lib has been set to the default library path, when I put the three JAR files of Microsoft JDBC Driver: msbase.jar, MSSQLServer.jar, Msutil.jar to% Java_Home% LIB After the middle (% java_home% / jre / lib) has also been tested, and the corresponding classpath, the result is the same), and then the JSP page is running, but the driver class library is still not prompted. Does Tomcat identifies the class libraries in your COMMON / LIB directory?

4. Connect the JSP code of SQL Server 2000 <% @ page import = "java.lang. *, Java.io. *, java.sql. *, Java.util. *" Contenttype = "text / html; charSet = EUC_CN "%>

<%

Class.Forname ("com.microsoft.jdbc.sqlserver.sqlserverdriver). NewInstance ();

String URL = "JDBC: Microsoft: SQLServer: // localhost: 1433; DatabaseName = OA"; // OA is the database name

String User = "sa";

String password = ""

Connection conn = drivermanager.getConnection (URL, User, Password);

Statement Stmt = Conn.createStatement (ResultSet.Type_Scroll_Sensitive, ResultSet.concur_Updata);

String SQL = "SELECT * from members_info"; // Members_info is a table name

ResultSet RS = Stmt.executeQuery (SQL);

While (rs.next ())

{

%>

Your first field content is: <% = rs.getstring (1)%>

Your second field content is: <% = rs.getstring (2)%>

<%

}

%>

<% out.print ("Database Success, Congratulations");%>

<%

Rs.close ();

Stmt.close ();

CONN.CLOSE ();

%>

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

New Post(0)