Tutorials to .com

Tutorials to .com » Jsp » Database » JSP to connect SQL Server 2000 system configuration

JSP to connect SQL Server 2000 system configuration

Print View , by: iSee ,Total views: 18 ,Word Count: 1459 ,Date: Sat, 18 Apr 2009 Time: 9:06 PM

:---- First installed J2SDK:
SUN the official site (http://java.sun.com) to download the J2SDK installation file: j2sdk-1_4_2_04-windows-i586-p.exe, installed after download J2SDK; After installation, set up environment variables: My computer High --- --- --- attribute environment variable;

Select --- system Variables (S):

Set JAVA_HOME environment variable:

--- Click New, enter the variable name: JAVA_HOME

Enter the variable value: D: \ java

(Assuming the J2SDK installed in the directory D: \ java under, since that is the J2SDK installation directory.)

--- And then to determine, this has been set up JAVA_HOME environment variable.

Set CLASSPATH environment variable:

--- Click New, enter the variable name: CLASSPATH

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

(The middle number of points "." And the semicolon ";" essential.)

--- And then to determine, this has been set up CLASSPATH environment variable.

Set PATH environment variable:

--- Click New, enter the variable name: PATH

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

(The middle number of points "." And the semicolon ";" essential.)

--- And then to determine, this has been set up JAVA_HOME environment variable.

Three environment variables set, the write a simple java program to test the success of J2SDK is installed:

In D: \ a directory under the new test; and then write the following procedure:
public class Test (
public static void main (String args []) (
System.out.println ( "This is a test program.");
)
)

During the above procedures will be saved as a file named Test.java files, stored in the directory D: \ test next.

And then open a command prompt window, cd to your test directory, and then type the following command

javac Test.java
java Test

Print out this time If you see This is a test program. The instructions to install if successful,

If you do not print this, you need to double-check your configuration.

If the above J2SDK installation is successful, the next to continue the installation of Tomcat:

The second step installation :---- Tomcat:

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

jakarta-tomcat-4.1.30.exe, installed after downloading. (Such as installed in D: \ Tomcat under.)

After installation, set the environment variables: My computer --- properties --- Advanced --- Environment variables;

Select --- System Variables (S):

Set CATALINA_HOME environment variable:

--- Click New, enter the variable name: CATALINA_HOME

Enter the variable value: D: \ Tomcat

--- And then to determine, this has been set up environment variables CATALINA_HOME.

Set CATALINA_BASE environment variable:

--- Click New, enter the variable name: CATALINA_BASE

Enter the variable value: D: \ Tomcat

--- And then to determine, this has been set up CATALINA_BASE environment variable.

And then modify the environment variable CLASSPATH, the Tomat under the installation directory common \ lib under the servlet.jar to the CLASSPATH in additional to,

CLASSPATH revised 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

Can then start tomcat, in the IE to access http://localhost:8080, if you see the tomcat welcome page so that the installation succeeded.

Tomcat installation if the above is successful, then continue with the installation jsp access SQL Server 2000 driver:

The third step to install JSP :---- visit to SQL Server 2000 driver:

From Microsoft's website to download the driver: SQL Server 2000 For JDBC drivers, just search in Google in there.

And then it installed. (Such as the installation directory is D: QLDriverForJDBC.)

And then must be installed in the lib directory of the three jar files under the directory:

msbase.jar, mssqlserver.jar, msutil.jar copy to the Tomcat directory common \ lib directory, and then, modify environment variables in the CLASSPATH,
To SQL Server 2000 For JDBC driver under the installation directory
D: QLDriverForJDBC \ lib \ msbase.jar; D: QLDriverForJDBC \ lib \ mssqlserver.jar;
D: QLDriverForJDBC \ msutil.jar;
In additional to the CLASSPATH, CLASSPATH amended 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

Must restart the Tomcat!

The purpose of this is, jsp page in the compiler does not arise in the course of sql server driver library can not find the problem

Write a simple test to connect to SQL Server 2000 code of the JSP

<% @ 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 database for your 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: <% = rs.getString (1)%> <br>
The second field of your content: <% = rs.getString (2)%> <br>
<%)%>
<% Out.print ( "database operations successful, congratulate you");%>
<% Rs.close ();
stmt.close ();
conn.close ();
%>
</ body>
</ html>

The above JSP code will be saved as sql_test.jsp, on the / Root directory.

Type in the address: http://localhost:8080/sql_test.jsp, If all the configuration is successful, it will be shown as follows:

Your first field says: 1
The second field of your content: New Hire - Job not specified
Your first field says: 2
The second field of your content for: Chief Executive Officer
Your first field says: 3
The second field of your content for: Business Operations Manager
Your first field says: 4
The second field of your content: Chief Financial Officier
Your first field says: 5
The second field of your content: Publisher
Your first field says: 6
The second field of your content: Managing Editor
Your first field says: 7
Your content for the second field: Marketing Manager
Your first field says: 8
The second field of your content for: Public Relations Manager
Your first field says: 9
The second field of your content: Acquisitions Manager
Your first field says: 10
The second field of your content: Productions Manager
Your first field says: 11
The second field of your content for: Operations Manager
The first field of your content for: 12
The second field of your content: Editor
Your first field says: 13
The second field of your content for: Sales Representative
Your first field says: 14
The second field of your content: Designer
database operations successful, congratulate you cover all of the above relevant 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


Jsp And Database Articles


Can't Find What You're Looking For?


Rating: Not yet rated

Comments

No comments posted.