# Looking for java implementation

**URL:** https://discuss.elastic.co/t/looking-for-java-implementation/144396
**Category:** Elasticsearch
**Created:** [August 14, 2018, 7:54pm UTC](https://discuss.elastic.co/t/looking-for-java-implementation/144396 "2018-08-14T19:54:49Z")
**Posts on this page:** 5
**Page:** 1

<div class="post-metadata">

### Author: ![aliyesami](https://avatars.discourse-cdn.com/v4/letter/a/ecb155/32.png) [@aliyesami](https://discuss.elastic.co/u/aliyesami)
#### Post date: [August 14, 2018, 7:54pm UTC](https://discuss.elastic.co/t/looking-for-java-implementation/144396/1 "2018-08-14T19:54:49Z")

</div>

can I call this elasticsearch-SQL command from java ? if yes can someone tell me how

> curl -X POST [http://hadoop1:9200/\_xpack/sql?format=txt](http://hadoop1:9200/_xpack/sql?format=txt) -H 'Content-Type: application/json' -d '{"query": "SELECT \* FROM product WHERE prodid = 758677748 "}'

---

<div class="post-metadata">

### Author: ![Andrei\_Stefan](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/andrei_stefan/32/47533_2.png) [@Andrei\_Stefan](https://discuss.elastic.co/u/Andrei_Stefan)
#### Post date: [August 16, 2018, 1:35pm UTC](https://discuss.elastic.co/t/looking-for-java-implementation/144396/2 "2018-08-16T13:35:06Z")

</div>

Hi @aliyesami,  
For Java access to ES-SQL features, you can use the JDBC driver. You have some starting point here, in the [documentation](https://www.elastic.co/guide/en/elasticsearch/reference/master/sql-jdbc.html).

---

<div class="post-metadata">

### Author: ![aliyesami](https://avatars.discourse-cdn.com/v4/letter/a/ecb155/32.png) [@aliyesami](https://discuss.elastic.co/u/aliyesami)
#### Post date: [August 16, 2018, 8:55pm UTC](https://discuss.elastic.co/t/looking-for-java-implementation/144396/3 "2018-08-16T20:55:24Z")

</div>

this document I already followed and have installed jdbc. any working example available to any kind of ES query or creating index?

---

<div class="post-metadata">

### Author: ![Andrei\_Stefan](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/andrei_stefan/32/47533_2.png) [@Andrei\_Stefan](https://discuss.elastic.co/u/Andrei_Stefan)
#### Post date: [August 17, 2018, 6:58am UTC](https://discuss.elastic.co/t/looking-for-java-implementation/144396/4 "2018-08-17T06:58:51Z")

</div>

There is a starting point in the page I already referenced about getting the Connection to Elasticsearch and initiating a request (a PreparedStatement). The `PreparedStatement` can have parameters and they are specified in the query itself as `?` (question marks). This is your typical JDBC access to a database, so if you are familiar with that, there is no difference between accessing a MySQL database or accessing Elasticsearch through the SQL plugin.

Please, do remember something: with ES-SQL JDBC (and ES-SQL in general) you cannot create an index, you cannot add, delete or update documents, only reads are permitted.

To get you started with something, here is a very simple example (a bit more than what it's in the documentation):

```auto
		String url = "jdbc:es://localhost:9200/";
		Connection conn = DriverManager.getConnection(url);
		
		PreparedStatement statement = conn.prepareStatement("SELECT some_id, some_date, prodid FROM product WHERE prodid = ?");
		statement.setLong(1, 758677748L);
		
		ResultSet results = statement.executeQuery();
		while (results.next()) {
			// do something with the results
			results.getInt("some_id");
			results.getDate("some_date");
			System.out.println(results.getLong("prodid"));
			System.out.println(results.getLong(3));
		}

```

---

<div class="post-metadata">

### Author: ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)
#### Post date: [September 14, 2018, 6:58am UTC](https://discuss.elastic.co/t/looking-for-java-implementation/144396/5 "2018-09-14T06:58:51Z")

</div>

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.
