JSP connection SQL Server 2000 system configuration

Source: Internet
Author: User
Tags continue sql server driver mssqlserver variables stmt variable root directory tomcat
Js|server First step:----Install J2SDK:
Download J2SDK installation files to the Sun official site (http://java.sun.com): j2sdk-1_4_2_04- Windows-i586-p.exe, download and install the J2SDK after installation, set environment variables: My Computer---attributes---advanced---environment variables;

Select---system variable (S):
 
To set the JAVA_HOME environment variable:

Click---New and enter in the variable name: java_home

Enter the value of the variable: D:\Java

(assuming J2SDK is installed in the directory D:\Java, it is the J2SDK installation directory anyway.) )

Then---determine that the JAVA_HOME environment variable has been set up to this.

To set the CLASSPATH environment variable:

Click---New and enter in the variable name: CLASSPATH

Enter the value of the variable: D:\Java\bin.;D: \ Java\lib;d:\java\lib\dt.jar;d:\java\lib\tools.jar

(The middle point number ".") and semicolon ";" Essential. )

Then---determine that the CLASSPATH environment variable has been set up to this.

To set the PATH environment variable:

Click---New and enter in the variable name: PATH

Enter the value of the variable: D:\Java.;D: \ Java\bin

(The middle point number ".") and semicolon ";" Essential. )

Then---determine that the JAVA_HOME environment variable has been set up to this.

After the three environment variables are set, write a simple Java program to test whether the J2SDK has been installed successfully:

Create a new directory test under D:\, and then write the following program:
public class Test {
public static void Main (String args[]) {
System.out.println ("This are a test program.");
}
}

Save the above program as a file named Test.java, saved under the directory D:\test.

Then open the Command Prompt window, the CD to your test directory, and then type the following command

Javac Test.java
Java Test

At this point, if you see the print this is a test program, the installation is successful.

If you do not print out this sentence, you need to carefully check your configuration.

If the above J2SDK installation succeeds, continue with the Tomcat installation:

Step Two:----Install Tomcat:

To the Tomcat official site (http://www.apache.org/dist/jakarta/tomcat-4/) to download tomcat:

Jakarta-tomcat-4.1.30.exe, install after downloading. (for example, install under D:\Tomcat.) )

After installation, set environment variables: My Computer---attributes---advanced---environment variables;

Select---system variable (S):

To set the CATALINA_HOME environment variable:

Click---New and enter in the variable name: catalina_home

Enter the value of the variable: D:\Tomcat

Then---determine that the catalina_home environment variable has been set up to this.

To set the CATALINA_BASE environment variable:

Click---New and enter in the variable name: catalina_base

Enter the value of the variable: D:\Tomcat

Then---determine that the catalina_base environment variable has been set up to this.

Then modify the classpath in the environment variable and append the Servlet.jar under the Tomat installation directory to Classpath,

The modified classpath is as follows:

classpath=d:\java\bin;;D: \ Java\lib;d:\java\lib\dt.jar;d:\java\lib\tools.jar;
D:\Tomcat\common\lib Ervlet.jar

Then you can start Tomcat, access http://localhost:8080 in IE, and if you see the Tomcat Welcome page, the installation is successful.

If the above Tomcat installation succeeds, then continue installing the JSP Access driver for SQL Server 2000:

Step Three:----Install the JSP to access the SQL Server 2000 driver:

Download the driver from Microsoft's Web site: SQL Server for JDBC driver, random search in Google.

And then install it well. (For example, the installation directory is D:QLDRIVERFORJDBC.) )

You must then have three jar files under the Lib directory in the installation directory:

Msbase.jar,mssqlserver.jar,msutil.jar Copy to the Common\lib directory under the Tomcat directory, and then modify the classpath in the environment variable,
The SQL Server for JDBC driver installation directory
D:qldriverforjdbc\lib\msbase.jar;d:qldriverforjdbc\lib\mssqlserver.jar;
D:qldriverforjdbc\msutil.jar;
Append to Classpath, the modified classpath is as follows:

classpath=d:\java\bin;;D: \ Java\lib;d:\java\lib\dt.jar;
_d:\java\lib\tools.jar;d:\lubeetomcat\common\lib Ervlet.jar;
_d:qldriverforjdbc\lib\msbase.jar;d:qldriverforjdbc\lib\mssqlserver.jar;
D:qldriverforjdbc\msutil.jar

Tomcat! must be restarted

The purpose of this is that the JSP page does not appear to be unable to find a SQL Server Driver class library during the compilation process

Write a simple JSP code to test the connection to SQL Server 2000

<%@ page import= "java.lang.*, java.io.*, java.sql.*, java.util.*" contenttype= "text/html;charset=gb2312"%>
<body>
<% class.forname ("Com.microsoft.jdbc.sqlserver.SQLServerDriver"). newinstance ();
String url= "Jdbc:microsoft:sqlserver://localhost:1433;databasename=pubs";
Pubs for your database of
String user= "SA";
String password= "admin";
Connection conn= drivermanager.getconnection (Url,user,password);
Statement stmt=conn.createstatement (resultset.type_scroll_sensitive,resultset.concur_updatable);
String sql= "Select Job_id,job_desc from Jobs";
ResultSet rs=stmt.executequery (SQL);
while (Rs.next ()) {%>
Your first field content is: <%=rs.getstring (1)%><br>
The contents of your second field are: <%=rs.getstring (2)%><br>
<%}%>
<% out.print ("Successful database operation, congratulations"); %>
<% Rs.close ();
Stmt.close ();
Conn.close ();
%>
</body>

Save the JSP code above as sql_test.jsp and put it in the/root directory.

Enter in Address: http://localhost:8080/sql_test.jsp, if all configurations are successful, it will appear as follows:

Your first field content is: 1
The contents of your second field are: New hire-job not specified
Your first field content is: 2
Your second field content is: Chief Executive Officer
Your first field content is: 3
Your second field content is: Business Operations Manager
Your first field content is: 4
Your second field content is: Chief Financial Officier
Your first field content is: 5
Your second field content is: Publisher
Your first field content is: 6
Your second field content is: Managing Editor
Your first field content is: 7
Your second field content is: Marketing Manager
Your first field content is: 8
Your second field content is: public Relations Manager
Your first field content is: 9
Your second field content is: Acquisitions Manager
Your first field content is: 10
Your second field content is: Productions Manager
Your first field content is: 11
Your second field content is: Operations Manager
Your first field content is: 12
Your second field content is: Editor
Your first field content is: 13
Your second field content is: Sales representative
Your first field content is: 14
Your second field content is: Designer
Database operation successful, congratulations!
 
All of the above relate to the relevant conditions:

Operating system: Window Server
J2SDK version: J2sdk-1_4_2_04-windows
Tomcat version: jakarta-tomcat-4.1.30
Local database: SQL Server 2000



Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.