JSP connection to SQL Server 2000

Source: Internet
Author: User
Tags mssqlserver
I used to use Asp.net all the time. Due to the needs of the project, I needed to learn about JSP and JSF. I tested yesterday and used JSP to connect to the database of SQL Server 2000. I found some information on the Internet, some problems have also been encountered. The following are some documents: 1, Pass JDBC-ODBC Connection SQL Server 2000JSP file <% @ page contenttype = "text/html; charset = gb2312" %> <% @ page import = "Java. SQL. * "%> <HTML> <body> <% class. forname ("Sun. JDBC. ODBC. jdbcodbcdriver "); connection con = drivermanager. getconnection ("JDBC: ODBC: test"); statement stmt = con. createstatement (); string SQL = "select * From t31001"; resultset rs = stmt.exe cutequery (SQL); While (RS. next () {string a = Rs. getstring (1); %> <Table> <tr> <TD> <% = A %> </TD> <TD> <% = Rs. getstring (2) %> </TD> <a href = "Edit. jsp? Id = <% = A %> "> edit </a> </TD> <a href =" Del. jsp? Id = <% = A %> "> Delete </a> </TD> </tr> </table> <% }%> <% Rs. close (); stmt. close (); con. close (); %> <a href = "add. JSP "> added </a> </body> 2, Pass SQL Server 2000 JDBC driver Connect SQL Server 20001. Download The JDBC driver of sqlserver2000. At the Microsoft site there is this driver: Window operating system http://www.uncj.com/upload/files/ms_jdbc_setup.exehttp://download.microsoft.com/download/3/0/f/30ff65d3-a84b-4b8a-a570-27366b2271d8/setup.exe UNIX operating system mssqlserver.tar http://download.microsoft.com/download/3/0/f/30ff65d3-a84b-4b8a-a570-27366b2271d8/mssqlserver.tar
Install jdbcto execute the ms_jdbc_setup.exe executable file. You only need to click Next to finish to complete the installation. Note: (1) the default installation path of ms_jdbc_setup is C:/program files/Microsoft SQL Server 2000 driver for JDBC (2) version 2.2.0022) this only supports Microsoft SQL Server 2000 driver for JDBC (3). The three jar files under the/lib/installation directory are the JDBC driver core msbase. jarmssqlserver. jarmsutil. jar 3. Add the Three jar files mentioned in (3) to the environment variable to 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 we do not recommend this. 4. Test the 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: sqlserver: // localhost: 1433; databasename = acfv3"; string user = "sa"; string Password = ""; connection conn = drivermanager. getconnection (URL, user, password); statement stmt = Conn. createstatement (Res Ultset. type_scroll_sensitive, resultset. concur_updatable); string SQL = "select * From t31001"; resultset rs1_stmt.exe cutequery (SQL); While (RS. next () {%> <Table> <tr> <TD> <% = Rs. getstring (1) %> </TD> <% = Rs. getstring (2) %> </TD> </tr> </table> <% }%> <% Rs. close (); stmt. close (); Conn. close (); %> </body>
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.