The first step:----Install J2SDK:
Go to SUN official website ( http://java.sun.com ) to download the J2SDK installation file: j2sdk-1_4_2_04-windows-i586-p.exe, and install J2SDK after downloading; After installation, set the environment variables: My Computer---Properties---Advanced---Environment Variables;
Select---System Variables (S):
Set the JAVA_HOME environment variable:
Click --- New, enter in the variable name: JAVA_HOME
and enter in the variable value: D:Java
(assuming that J2SDK is installed in the directory D:Java, which is the installation directory of J2SDK anyway.)
Then ---OK, the JAVA_HOME environment variable has been set now.
Set the CLASSPATH environment variable:
Click --- New, enter in the variable name: CLASSPATH
and enter in the variable value: D:Javabin;.;D:Javalib;D:Javalibdt. jar;D:Javalibtools.jar
(The period "." and semicolon ";" in the middle are essential.)
Then --- confirm, the CLASSPATH environment variable has been set.
Set the PATH environment variable:
Click --- New, enter in the variable name: PATH
Enter in the variable value: D:Java;.;D:Javabin
(the middle period "." and semicolon " ;" is essential.)
Then --- confirm, the JAVA_HOME environment variable has been set.
After setting the three environment variables, write a simple java program to test whether J2SDK has been successfully installed:
Create a new directory test under D:; then 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 in the directory D:test.
Then open a command prompt window, cd to your test directory, and then type the following command
javac Test.java
java Test
at this time, the installation is successful.
If this sentence is not printed out, you need to carefully check your configuration.
If the above J2SDK is successfully installed, continue to install Tomcat:
Step 2: ----Install Tomcat:
Download from the tomcat official site ( http://www.apache.org/dist/jakarta/tomcat-4/ ) tomcat:
jakarta-tomcat-4.1.30.exe, download and install. (For example, install it under D:Tomcat.)
After installation, set the environment variables: My Computer---Properties---Advanced---Environment Variables;
Select---System Variables (S):
Set the CATALINA_HOME environment variable :
Click --- New, enter in the variable name: CATALINA_HOME,
enter in the variable value: D:Tomcat
and then --- OK, now the CATALINA_HOME environment variable has been set.
Set the CATALINA_BASE environment variable:
Click --- New, enter: CATALINA_BASE in the variable name,
enter: D:Tomcat in the variable value
, and then --- OK. The CATALINA_BASE environment variable has been set.
Then modify the CLASSPATH in the environment variable and append servlet.jar under commonlib in the Tomat installation directory to CLASSPATH.
The modified CLASSPATH is as follows:
CLASSPATH=D:Javabin;.;D:Java lib;D:Javalibdt.jar;D:Javalibtools.jar;
D:Tomcatcommonlibservlet.jar
Then you can start tomcat and visit http://localhost:8080 in IE. If you see the tomcat welcome page, the installation is successful.
If the tomcat installation above is successful, continue to install the driver for JSP to access SQL Server 2000:
Step 3: ----Install the driver for JSP to access SQL Server 2000:
Download the driver from Microsoft's website: SQL Server 2000 For JDBC driver, just search it in Google.
Then install it. (For example, the installation directory is D:SQLDriverForJDBC.)
Then you must copy the three jar files in the lib directory in the installation directory:
msbase.jar, mssqlserver.jar, msutil.jar to the commonlib directory in the Tomcat directory. After that, Modify CLASSPATH in the environment variable,
Put the SQL Server 2000 For JDBC driver in the installation directory
D:SQLDriverForJDBClibmsbase.jar;D:SQLDriverForJDBClibmssqlserver.jar;
D:SQLDriverForJDBCmsutil.jar;
Append to CLASSPATH. The modified CLASSPATH is as follows:
CLASSPATH=D:Javabin;.;D:Javalib;D:Javalibdt.jar;
_D:Javalibtools.jar;D:LubeeTomcatcommonlibservlet.jar;
_D:SQLDriverForJDBClibmsbase.jar;D:SQLDriverForJDBClibmssqlserver.jar;
D:SQLDriverForJDBCmsutil.jar
Tomcat must be restarted!
The purpose of this is that the jsp page will not have the problem of not being able to find the 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" %>
<html>
<body>
<% Class.forName("com.microsoft.jdbc.sqlserver.SQLServerDriver").newInstance();
String url="jdbc:microsoft:sqlserver://localhost:1433;DatabaseName=pubs";
//pubs is the String user="sa" of your database;
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>
Your second field content is: <%=rs.getString(2)%><br>
<% } %>
<% out.print("Database operation is successful, congratulations"); %>
<% rs.close();
stmt.close();
conn.close();
%>
</body>
</html>
Save the above JSP code as sql_test.jsp and place it in the /Root directory.
Enter: http://localhost:8080/sql_test.jsp in the address. If all configurations are successful, it will be displayed as follows:
Your first field content is: 1
Your second field content is: 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 reads: Business Operations Manager
Your first field content is: 4
Your second field reads: Chief Financial Officer
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 reads: Marketing Manager
Your first field content is: 8
Your second field reads: Public Relations Manager
Your first field content is: 9
Your second field reads: Acquisitions Manager
Your first field content is: 10
Your second field reads: 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
The database operation is successful, congratulations on all the above related conditions:
Operating system: Window 2000 Server
J2SDK version: j2sdk-1_4_2_04-windows
Tomcat version: jakarta-tomcat-4.1.30
Local database: SQL Server 2000