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.