Troubleshoot a JDBC Datasource
The JDBC connector fetches documents from a relational database via SQL queries. Under the hood, this connector implements the Solr DataImportHandler (DIH) plugin.
When using the JDBC connector, it is recommended that you work closely with your database administrator to formulate efficient and robust queries.
One source of possible problems is the driver being used. In some cases, indexing may fail due to problems with the driver, in particular older versions of Oracle’s JDBC driver. If you have checked that your connection information is correct and your database is allowing the connection, you may want to research if there are any known bugs with the driver you are using.
With Oracle databases, note that column names not enclosed in double-quotes are converted to upper-case, but Solr field names are case sensitive. If your column-to-field mapping is not happening properly, check your SQL statement for any lower-case names not enclosed in double-quotes.
Dates can also be problematic. Solr has a different date format than many relational databases. If you want date and time fields to be indexed properly, you may need to convert database dates into the proper format using date/string convert functions. In Oracle this is the TO_CHAR
function; in Microsoft SQL, this is the DATEPART
function.
In MySQL databases, dates are allowed to be 0-strings, such as 0000-00-00
, which is not acceptable to JDBC. If you have legacy date data you may need to add the query parameter zeroDateTimeBehavior=convertToNull
to your JDBC request string, as in jdbc:mysql://localhost/myDatabase?zeroDateTimeBehavior=convertToNull
. This will convert the zero-string dates to null values that can be added to the index.
Finally, database timeouts are another problematic area. There are several possible solutions to this, from increasing the timeout in the JDBC request (with netTimeoutForStreamingResults
), altering the SQL statement to page the results, or dumping the records to CSV and indexing them with another connector.