[role="xpack"] [[sql-jdbc]] == SQL JDBC Elasticsearch's SQL jdbc driver is a fully featured JDBC driver for Elasticsearch. TODO add example of resolving the artifact in maven and gradle. You can connect to it using the two APIs offered by JDBC, namely `java.sql.Driver` and `DriverManager`: ["source","java",subs="attributes,callouts,macros"] -------------------------------------------------- include-tagged::{jdbc-tests}/JdbcIntegrationTestCase.java[connect-dm] -------------------------------------------------- <1> The server and port on which Elasticsearch is listening for HTTP traffic. The port is usually 9200. <2> Properties for connecting to Elasticsearch. An empty `Properties` instance is fine for unsecured Elasticsearch. or `javax.sql.DataSource` through ["source","java",subs="attributes,callouts,macros"] -------------------------------------------------- include-tagged::{jdbc-tests}/JdbcIntegrationTestCase.java[connect-ds] -------------------------------------------------- <1> The server and port on which Elasticsearch is listening for HTTP traffic. The port is usually 9200. <2> Properties for connecting to Elasticsearch. An empty `Properties` instance is fine for unsecured Elasticsearch. Which one to use? Typically client applications that provide most configuration parameters in the URL rely on the `DriverManager`-style while `DataSource` is preferred when being _passed_ around since it can be configured in one place and the consumer only has to call `getConnection` without having to worry about any other parameters. To connect to a secured Elasticsearch server the `Properties` should look like: ["source","java",subs="attributes,callouts,macros"] -------------------------------------------------- include-tagged::{security-tests}/JdbcSecurityIT.java[admin_properties] -------------------------------------------------- Once you have the connection you can use it like any other JDBC connection. For example: ["source","java",subs="attributes,callouts,macros"] -------------------------------------------------- include-tagged::{jdbc-tests}/SimpleExampleTestCase.java[simple_example] --------------------------------------------------