an ODBC driver?
SQL Server can connect to a non-SQL Server database by using a linked server. The linked server mechanism can use a piece of middleware known as an ODBC driver to connect SQL Server to third-party back ends such Oracle, MySQL, and Salesforce.
The equivalent of an ODBC driver for a Java database is a JDBC driver. Microsoft do not provide a linked server interface that supports JDBC. Rather, you need to use the ODBC linked server interface (Microsoft OLE DB Provider for ODBC Drivers) with an ODBC driver than can translate between ODBC and JDBC. For example, the ODBC-JDBC Gateway. The ODBC-JDBC Gateway connects an application that uses ODBC to a database that's accessible through JDBC. To the application, the ODBC-JDBC Gateway is an ODBC driver. To the JDBC driver, the ODBC-JDBC Gateway is a Java application.
Use the ODBC-JDBC Gateway to:
For installation instructions, refer to the ODBC-JDBC Gateway documentation.
Before you can use the ODBC-JDBC Gateway to connect your ODBC application to JDBC, you need to configure a system ODBC data source. An ODBC data source stores the connection details for the target database.
You configure ODBC data sources in ODBC Data Source Administrator, which is included with Windows. There are two versions of ODBC Data Source Administrator, one 32-bit, one 64-bit. You need to run the 32-bit version if your SQL Server instance is 32-bit. You need to run the 64-bit version if your SQL Server instance is 64-bit.
To find out which version of SQL Server you have, connect to your SQL Server instance, and then run this SQL statement:
select SERVERPROPERTY('edition')
To run the 32-bit ODBC Data Source Administrator, in the Windows Run dialog box, enter:
%windir%\syswow64\odbcad32.exe
To run the 64-bit ODBC Data Source Administrator, in the Windows Run dialog box, enter:
odbcad32.exe
Use ODBC Data Source Administrator to create your ODBC-JDBC Gateway data source.
Setting | Description |
---|---|
DSN | OJG_DSN |
User Name | The user name for your Java back end, if required. |
Password | The password for user name. |
Driver Class | Refer to your JDBC driver documentation for the value you need to enter here. |
Class Path | Use the Add button to browse to your JDBC driver JAR or ZIP file. |
URL | The JDBC URL used by your JDBC driver to connect to the Java back end. Refer to your JDBC driver documentation for the syntax that you need to use. |
You need to log on with an account that is a member of the SQL Server sysadmin
fixed server role to create a linked server.
OJG
.SQL Server verifies the linked server by testing the connection.
PATH
environment variable. The ODBC-JDBC Gateway Setup program adds entries for the driver to the System PATH
. Restarting the instance makes these changes available to SQL Server, allowing it to load the ODBC-JDBC Gateway.A four-part table name has the format:
server_name.[database_name].[schema_name].table_name
Depending on your Java back end, you may need to omit the database name and schema. For example:
SELECT * from OJG...my_table
OPENQUERY
function. For example:
SELECT * FROM OPENQUERY(OJG, 'SELECT * FROM my_table')
SQL Server sends pass-through queries as uninterpreted query strings to the ODBC-JDBC Gateway. This means that SQL Server does not apply any kind of logic to the query or try to estimate what that query will do.