Jsp jtds connection to SQLServer 2000

Source: Internet
Author: User

 

Jsp jtds connection to SQLServer 2000

 

How does jsp connect to the SQL server 2000 database? In addition to jdbc, there is also a jtds connection method.

 

Connect to the SQL Server database through JTDS JDBC Driver, the Driver file name is jtds-1.2.jar, download path is (http://sourceforge.net/project/showfiles.php? Group_id = 33291), the driver supports Microsoft SQL Server (6.5, 7.0, 2000 and 2005) and Sybase, and implements JDBC3.0, which is free of charge.

Before configuration, make sure that the configuration is completed between eclipse + myeclipse + tomcat to ensure successful configuration of the following operations.


Download unzip will find the jtds-1.2.jar, copy it to E: \ Tomcat 7.0 \ lib directory, OK.

 

 

Code:

 

<% @ Page language = "java" import = "java. util. *" pageEncoding = "UTF-8" %>
<% @ Page import = "java. SQL. *" %>
<%
String path = request. getContextPath ();
String basePath = request. getScheme () + ": //" + request. getServerName () + ":" + request. getServerPort () + path + "/";
%>

<! Doctype html public "-// W3C // dtd html 4.01 Transitional // EN">
<Html>
<Body>
<%
Class. forName ("net. sourceforge. jtds. jdbc. Driver"). newInstance ();
String url = "jdbc: jtds: sqlserver: // localhost: 1433/pubs ";
String user = "sa ";
String password = "yourpassword ";
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 code as index. jsp in the project directory. You can.

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.