Добавил:
Upload Опубликованный материал нарушает ваши авторские права? Сообщите нам.
Вуз: Предмет: Файл:
ts_tier_2_012010.doc
Скачиваний:
0
Добавлен:
01.07.2025
Размер:
1.25 Mб
Скачать
  1. How do I Connect to an ms sql Database Source with .Jsp?

The following steps will allow you to make a simple connection to an MS SQL database using .jsp: Obtain the JDBC libraries for MS SQL

Microsoft has made standard libraries according to the JDBC specification published by Sun Microsystems. You can download the latest library directly from Microsoft (note that you must login with a Microsoft Passport, or create one): http://www.microsoft.com/sql/downloads/jdbcregister.asp

There is a .tar and a setup.exe file – you only require the setup.exe file if you wish to have all the libraries installed on a Windows system. The .tar file contains everything you require otherwise. It will expand into an msjdbc.tar file, which contains the appropriate libraries.

  1. Upload appropriate libraries to your /public/web-inf/lib location

There are several files that come with the /Microsoft JDBC libraries, however you only need three.  The files should be in the /lib folder of the archive and are named:

    • msbase.jar

    • MSSQLserver.jar

    • msutil.jar

Upload these files to the /public/WEB-INF/lib/ directory.  You must wait up to 24 hours for the addition of the new Java libraries to be loaded by the JSP server.

  1. How do I Create a test .Jsp file?

There are THREE important options that must be configured to ensure that you are setup correctly:

a) DB_NAME should be changed to your database name b) USERNAME should be changed to your username c) PASSWORD should be changed to your password

The DB_NAME and USERNAME are available from your Web Service Provider.Upload this file into your /public/ web directory.  You should be able to test this by going to your website: http://www.yourdomainname.tld/MS SQLtest.jsp

Copy and paste the following text into an MSSQLtest.jsp file: 

<%@ page import="java.sql.*" %> <% try { Class.forName("com.microsoft.jdbc.sqlserver.SQLServerDriver"); Connection Conn =     DriverManager.getConnection("jdbc:microsoft:sqlserver://MSSQL.megasqlservers.com;DatabaseName=“DB_NAME","USERNAME","PASSWORD""); out.println("Connected!"); }  catch(ClassNotFoundException e) { out.println("Driver not found."); out.println(e.toString()); //throw new UnavailableException(this, "Class not found."); } catch(SQLException e) { out.println("You have an error: "); out.println(e.toString()); //throw new UnavailableException(this, "Cannot connect with the specified database."); } %>

  1. Are there any potential issues ?

You get an error message that starts with “Driver not found”

Ensure that you have uploaded the JAR file specified in step 2 into the appropriate directory and have waited up to 24 hours for the changes to take effect. You get an error message that starts with “You have an error: java.sql.SQL Exception” Please read the contents of the error carefully.  This means that you have supplied incorrect information. 

Соседние файлы в предмете [НЕСОРТИРОВАННОЕ]