# Facing error while i am trying to connect my JAVA connection class to ElasticSearch

**URL:** <https://discuss.elastic.co/t/facing-error-while-i-am-trying-to-connect-my-java-connection-class-to-elasticsearch/229792>\
**Category:** Elasticsearch\
**Created:** [April 25, 2020, 8:41pm UTC](https://discuss.elastic.co/t/facing-error-while-i-am-trying-to-connect-my-java-connection-class-to-elasticsearch/229792 "2020-04-25T20:41:10Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Rahul\_layall](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/rahul_layall/32/46899_2.png) [@Rahul\_layall](https://discuss.elastic.co/u/Rahul_layall)\
**Post date:** [April 25, 2020, 8:41pm UTC](https://discuss.elastic.co/t/facing-error-while-i-am-trying-to-connect-my-java-connection-class-to-elasticsearch/229792/1 "2020-04-25T20:41:10Z")

</div>

Hello Sir,  
I have created a class in my JAVA project so that i can run SQL queries and fetch the result from Elastic Search

Here is my code:

package javaConn;

import java.sql.Connection;  
import java.sql.Driver;  
import java.sql.DriverManager;  
import java.sql.ResultSet;  
import java.sql.SQLException;  
import java.sql.Statement;  
import java.util.Properties;

public class SQLConn {

```
public static void main(String args[]){
	Connection conn;
	try
	{	
		String address = "jdbc:es://" + "10.199.62.140:9200";
		Properties properties = new Properties();
		properties.put("user", "userName");
		properties.put("password", "password");
	     conn = DriverManager.getConnection(address, properties);
		
		Statement stat=(Statement) conn.createStatement();
		boolean ret=stat.execute("Select * from index_name");
		if(ret){
			ResultSet rs = stat.getResultSet();
			while(rs.next())
			{	
			System.out.println("name :"+rs.getString(1));
			}
		}
}
	catch (SQLException e ) {
		System.out.println(e.getMessage());
		System.out.println(e);
	}
}

```

}

i am facing this error:

when i debugged the code then i find the error at this line i.e {boolean ret=stat.execute("Select \* from table\_name");}

Exception in thread "main" java.util.ServiceConfigurationError: org.elasticsearch.common.xcontent.XContentBuilderExtension: Provider org.elasticsearch.common.xcontent.XContentElasticsearchExtension could not be instantiated  
at java.util.ServiceLoader.fail(Unknown Source)  
at java.util.ServiceLoader.access$100(Unknown Source)  
at java.util.ServiceLoader$LazyIterator.nextService(Unknown Source)  
at java.util.ServiceLoader$LazyIterator.next(Unknown Source)  
at java.util.ServiceLoader$1.next(Unknown Source)  
at org.elasticsearch.common.xcontent.XContentBuilder.(XContentBuilder.java:118)  
at org.elasticsearch.xpack.sql.client.HttpClient.toXContent(HttpClient.java:142)  
at org.elasticsearch.xpack.sql.client.HttpClient.post(HttpClient.java:100)  
at org.elasticsearch.xpack.sql.client.HttpClient.query(HttpClient.java:80)  
at org.elasticsearch.xpack.sql.jdbc.JdbcHttpClient.query(JdbcHttpClient.java:68)  
at org.elasticsearch.xpack.sql.jdbc.JdbcStatement.initResultSet(JdbcStatement.java:160)  
at org.elasticsearch.xpack.sql.jdbc.JdbcStatement.execute(JdbcStatement.java:151)  
at javaConn.SQLConn.main(SQLConn.java:48)  
Caused by: java.lang.NoClassDefFoundError: org/joda/time/ReadableInstant  
at java.lang.Class.getDeclaredConstructors0(Native Method)  
at java.lang.Class.privateGetDeclaredConstructors(Unknown Source)  
at java.lang.Class.getConstructor0(Unknown Source)  
at java.lang.Class.newInstance(Unknown Source)  
... 11 more  
Caused by: java.lang.ClassNotFoundException: org.joda.time.ReadableInstant  
at java.net.URLClassLoader.findClass(Unknown Source)  
at java.lang.ClassLoader.loadClass(Unknown Source)  
at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)  
at java.lang.ClassLoader.loadClass(Unknown Source)  
... 15 more

---

<div class="post-metadata">

**Author:** ![Luca\_Belluccini](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/luca_belluccini/32/33239_2.png) [@Luca\_Belluccini](https://discuss.elastic.co/u/Luca_Belluccini)\
**Post date:** [April 26, 2020, 1:43am UTC](https://discuss.elastic.co/t/facing-error-while-i-am-trying-to-connect-my-java-connection-class-to-elasticsearch/229792/2 "2020-04-26T01:43:18Z")

</div>

> [@Rahul\_layall](#):
>
> Caused by: java.lang.ClassNotFoundException: org.joda.time.ReadableInstant

One of the columns is DateTime and the drive tries to build a `org.joda.time.ReadableInstant`, but you're missing the dependency.  
Can you try to add a dependency (and the `jar`) to `joda-time` ?

---

<div class="post-metadata">

**Author:** ![Rahul\_layall](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/rahul_layall/32/46899_2.png) [@Rahul\_layall](https://discuss.elastic.co/u/Rahul_layall)\
**Post date:** [April 29, 2020, 9:09am UTC](https://discuss.elastic.co/t/facing-error-while-i-am-trying-to-connect-my-java-connection-class-to-elasticsearch/229792/3 "2020-04-29T09:09:56Z")

</div>

Thank You Sir  
It worked and my problem is solved now

---

<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:** [May 27, 2020, 9:10am UTC](https://discuss.elastic.co/t/facing-error-while-i-am-trying-to-connect-my-java-connection-class-to-elasticsearch/229792/4 "2020-05-27T09:10:06Z")

</div>

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