JSP connection to SQL Server 2000 System Configuration

Source: Internet
Author: User
Tags sql server driver mssqlserver

Step 1: ---- install J2SDK:

To the SUN official site (http://java.sun.com) download J2SDK Installation File: j2sdk-1_4_2_04-windows-i586-p.exe, download and install J2SDK; after installation, set environment variables: My computer --- properties --- advanced --- environment variables;

Select --- system variable (S ):
 
Set the JAVA_HOME environment variable:

Click --- New and enter JAVA_HOME in the variable name.

Enter: D: \ Java in the variable value

(Assume that J2SDK is installed in the Directory D: \ Java, which is the installation directory of J2SDK .)

Then --- OK. The JAVA_HOME environment variable has been set here.

Set the CLASSPATH environment variable:

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

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

(The dot "." And Semicolon ";" in the middle are required .)

Then --- OK. Now the CLASSPATH environment variable has been set.

Set the PATH environment variable:

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

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

(The dot "." And Semicolon ";" in the middle are required .)

Then --- OK. The JAVA_HOME environment variable has been set here.

After setting the three environment variables, write a simple java program to test whether J2SDK has been installed successfully:

Create a directory test under D: \ and write the following program:
Public class Test {
Public static void main (String args []) {
System. out. println ("This is a test program .");
}
}

Save the above program as a file named Test. java and save it in the Directory D: \ test.

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

Javac Test. java
Java Test

If This is a test program is printed, the installation is successful,

If this statement is not printed, You need to carefully check your configuration.

If the above J2SDK is successfully installed, continue to install Tomcat:

Step 2: ---- install Tomcat:

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

Jakarta-tomcat-4.1.30.exe, installed after download. (For example, install it in D: \ Tomcat .)

After installation, set the environment variable: My computer --- properties --- advanced --- environment variable;

Select --- system variable (S ):

Set the CATALINA_HOME environment variable:

Click --- New and enter CATALINA_HOME in the variable name.

Enter: D: \ Tomcat in the variable value

Then --- OK. Now the CATALINA_HOME environment variable has been set.

Set the CATALINA_BASE environment variable:

Click --- New and enter CATALINA_BASE in the variable name.

Enter: D: \ Tomcat in the variable value

Then --- OK. Now the CATALINA_BASE environment variable has been set.

Then, modify the CLASSPATH in the environment variable and append the servlet. jar under the common \ lib under the Tomat installation directory to the CLASSPATH,

The modified CLASSPATH is as follows:

CLASSPATH = D: \ Java \ bin;.; D: \ Java \ lib \ dt. jar; D: \ Java \ lib \ tools. jar;
D: \ Tomcat \ common \ lib \ servlet. jar

Start tomcat and access http: // localhost: 8080 in IE. If you see the welcome page of tomcat, the installation is successful.

If tomcat is successfully installed, continue to install the driver for JSP access to SQL Server 2000:

Step 3: ---- install the JSP driver for accessing SQL Server 2000:

Download the driver from Microsoft's website: the SQL Server 2000 For JDBC driver, which is available on Google.

Then install it. (For example, the installation directory is D: \ SQLDriverForJDBC .)

Three jar files under the lib directory in the installation directory must be:

Copy msbase. jar, mssqlserver. jar, and msutil. jar to the common \ lib directory under the Tomcat directory, and modify the CLASSPATH in the environment variable,
Install the SQL Server 2000 For JDBC driver
D: \ SQLDriverForJDBC \ lib \ msbase. jar; D: \ SQLDriverForJDBC \ lib \ mssqlserver. jar;
D: \ SQLDriverForJDBC \ msutil. jar;
Append to CLASSPATH. The modified CLASSPATH is as follows:

CLASSPATH = D: \ Java \ bin;.; D: \ Java \ lib \ dt. jar;
_ D: \ Java \ lib \ tools. jar; D: \ LubeeTomcat \ common \ lib \ servlet. jar;
_ D: \ SQLDriverForJDBC \ lib \ msbase. jar; D: \ SQLDriverForJDBC \ lib \ mssqlserver. jar;
D: \ SQLDriverForJDBC \ msutil. jar

Tomcat must be restarted!

The purpose is that the SQL server driver Class Library cannot be found during the compilation of the jsp page.

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

<% @ Page import = "java. lang. *, java. io. *, java. SQL. *, java. util. * "contentType =" text/html; charset = gb2312 "%>
<Html>
<Body>
<% Class. forName ("com. microsoft. jdbc. sqlserver. SQLServerDriver"). newInstance ();
String url = "jdbc: microsoft: sqlserver: // localhost: 1433; DatabaseName = pubs ";
// Pubs for your database
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 rs1_stmt.exe cuteQuery (SQL );
While (rs. next () {%>
The content of your first field is: <% = rs. getString (1) %> <br>
Your second field content is: <% = rs. getString (2) %> <br>
<% }%>
<% Out. print ("database operation successful, congratulations"); %>
<% Rs. close ();
Stmt. close ();
Conn. close ();
%>
</Body>
</Html>

Save the preceding JSP code as SQL _test.jsp and put it in the/Root directory.

Enter http: // localhost: 8080/SQL _test.jsp in the address. If all configurations are successful, the following information is displayed:

The content of your first field is: 1
Your second field content is: New Hire-Job not specified
The content of your first field is: 2
Your second field content is: Chief Executive Officer
The content of your first field is: 3
Your second field content is: Business Operations Manager
The content of your first field is: 4
Your second field is: Chief Financial Officier
The content of your first field is: 5
Your second field content is: Publisher
The content of your first field is: 6
Your second field content is: Managing Editor
Your first field content is: 7
Your second field content is: Marketing Manager
The content of your first field is: 8
Your second field is Public Relations Manager.
The content of your first field is: 9
Your second field is Acquisitions Manager.
The content of your first field is: 10
Your second field content is: Productions Manager
Your first field content is: 11
Your second field is Operations Manager.
The content of your first field is: 12
Your second field content is: Editor
The content of your first field is: 13
Your second field is Sales Representative.
Your first field content is: 14
Your second field content is: Designer
Database Operation successful, congratulations
 
All the above content involves the following conditions:

Operating System: Window 2000 Server
J2SDK version: j2sdk-1_4_2_04-windows
Tomcat: 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.