Full Process of JSP connection to sqlserver

Source: Internet
Author: User
Tags mssqlserver

1. Download The JDBC driver of sqlserver2000Program.

This driver is available at the Microsoft Site:

Window Operating System

Http://www.uncj.com/upload/files/ms_jdbc_setup.exe

Http://download.microsoft.com/download/3/0/f/30ff65d3-a84b-4b8a-a570-27366b2271d8/setup.exe

 

Unix OS mssqlserver.tar

Http://download.microsoft.com/download/3/0/f/30ff65d3-a84b-4b8a-a570-27366b2271d8/mssqlserver.tar

 

Ii. Install JDBC

Execute the ms_jdbc_setup.exe executable file. You only need to click Next to finish to complete the installation.

Note:

(1) ms_jdbc_setup default installation path: C:/program files/Microsoft SQL Server 2000 driver for JDBC

(2) version 2.2.0022 only supports Microsoft SQL Server 2000 driver for JDBC.

(3) The Three jar files under the installation directory/lib/are the core of the JDBC driver.

Msbase. Jar

MSSQLServer. Jar

Msutil. Jar

 

3. Add the Three jar files mentioned in (3) to the environment variables.

Classpath:

D:/webserver/lib/msbase. jar; D:/webserver/lib/MSSQLServer. jar; D:/webserver/lib/msutil. Jar

Note: You can also copy the above three files to the java_home/JRE/lib/EXT directory where your JVM machine is located, but it is not recommended to do so.

 

Iv. Test

JSP file:

<% @ Page contenttype = "text/html; charset = gb2312" %>

<% @ Page import = "Java. SQL. *" %>

<HTML>

<Body>

<%

Class. forname ("com. Microsoft. JDBC. sqlserver. sqlserverdriver"). newinstance ();

String url = "JDBC: Microsoft: SQL SERVER: // localhost: 1433; databasename = haiguan ";

String user = "sa ";

String Password = "";

Connection conn = drivermanager. getconnection (URL, user, password );

Statement stmt = conn. createstatement (resultset. type_scroll_sensitive, resultset. concur_updatable );

String SQL = "select * From xt_user ";

Resultset rs1_stmt.exe cutequery (SQL );

While (Rs. Next ())

{

%>

The content of your first field is: <% = Rs. getstring (1) %>

Your second field content is: <% = Rs. getstring (2) %>

<%

}

%>

<% Out. Print ("database operation successful, congratulations"); %>

<%

Rs. Close ();

Stmt. Close ();

Conn. Close ();

%>

</Body>

</Html>

 

5. Notes

1. Make sure that your SQL service is in the startup status.

2. log on to the SQL Manager using sa or other users. (Some users use the NT user management mode when installing SQL. Some problems may occur here)

3. The first time you configure environment variables, you 'd better restart your computer.

4. Note the startup sequence of JVM and Database: Start the database first and then the JVM machine.

Note: After you stop the Web server and restart it, you are advised to have an interval of more than 10 seconds in the middle.

5. Pay attention to the network connectivity of the operating system.

A. the TCP/IP service is started.

B. Related IP addresses are configured. Some machines may use an automatically assigned IP address or configured IP address, but the IP address may not be found even if the network is disconnected.

6. In debugging, it is best for some machines to change the connection address localhost in (4) to the IP address of the database server, which is also the cause of attention 5.

 

 

 

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.