Jsp SQL Server connection learning experience

Source: Internet
Author: User
Tags sql server driver mssqlserver

Step 1 of jsp SQL Server connection: ---- 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 ". "And Semicolon"; "is 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:

 
 
  1. publicclassTest{  
  2. publicstaticvoidmain(Stringargs[]){  
  3. System.out.println("Thisisatestprogram.");  
  4. }  

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 of jsp SQL Server connection ---- install Tomcat:
◆ Tomcat official site point (http://www.apache.org/dist/jakarta/tomcat-4/) download tomcat: jakarta-tomcat-4.1.30.exe, download after installation. (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.
◆ Modify the CLASSPATH in the environment variable, and append the servlet. jar under common \ lib under the Tomat installation directory to the 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 \ 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 JSP driver to access SQL Server 2000:

Step 3 of jsp SQL Server connection: ---- install the driver for JSP access to SQL Server 2000:
◆ Download the driver from Microsoft's website: the SQL Server 2000 For JDBC driver. You can search For the driver on Google.
◆ 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 of this operation is that the SQL server driver Class Library cannot be found during jsp page compilation.
◆ Write a simple JSP code used to test the connection to SQL Server 2000:

 
 
  1. <% @Pageimport= "Java. lang. *, java. io. *, java. SQL. *, java. util.
    "ContentType= "Text/html;Charset=Gb2312"%>
  2. <Html>
  3. <Body>
  4. <% Class. forName ("com. microsoft. jdbc. sqlserver. SQLServerDriver"). newInstance ();
  5. Stringurl="Jdbc: microsoft: sqlserver: // localhost: 1433; DatabaseName = pubs";
  6. // Pubs for your database
  7. Stringuser="Sa";
  8. Stringpassword="Admin";
  9. Connectionconn=DriverManager. GetConnection (url, user, password );
  10. Statementstmt=Conn. CreateStatement
    (ResultSet. TYPE_SCROLL_SENSITIVE, ResultSet. CONCUR_UPDATABLE );
  11. Stringsql="Selectjob_id, job_descfromjobs";
  12. ResultSetrs=Stmt. ExecuteQuery (SQL );
  13. While (rs. next () {%>
  14. The content of your first field is: <% = rs. getString (1) %> <br>
  15. Your second field content is: <% = rs. getString (2) %> <br>
  16. <% }%>
  17. <% Out. print ("database operation successful, congratulations"); %>
  18. <% Rs. close ();
  19. Stmt. close ();
  20. Conn. close ();
  21. %>
  22. </Body>
  23. </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: NewHire-Jobnotspecified
The content of your first field is: 2
Your second field content is: ChiefExecutiveOfficer
The content of your first field is: 3
Your second field is BusinessOperationsManager.
The content of your first field is: 4
Your second field content is: chieffinw.alofficier
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 is ManagingEditor.
Your first field content is: 7
Your second field content is: MarketingManager
The content of your first field is: 8
Your second field is PublicRelationsManager.
The content of your first field is: 9
Your second field is AcquisitionsManager.
The content of your first field is: 10
Your second field is ProductionsManager.
Your first field content is: 11
Your second field is OperationsManager.
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 content is: SalesRepresentative
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: Window2000Server
J2SDK version: j2sdk-1_4_2_04-windows
Tomcat: jakarta-tomcat-4.1.30
Local Database: SQLServer2000

The above describes the jsp SQL Server connection learning experience.

  1. JSP development technical application details
  2. Detailed description of JSP development environment Configuration
  3. JScript, Java, JavaScript, and JSP Summary
  4. Detailed description of JSP development environment Configuration
  5. ASP and JSP comparison

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.