elasticsearch 6.3使用java代码连接jdbc遇到java.lang.NoSuchFieldError: LUCENE_5_2_1
Elasticsearch | 作者 es-learn | 发布于2018年07月06日 | 阅读数:6431
代码如下:
public class ESJdbcTest {
static String driver = "org.elasticsearch.xpack.sql.jdbc.jdbc.JdbcDriver";
static String elasticsearchAddress = "127.0.0.1:9200";
public static Properties connectionProperties(){
Properties properties = new Properties();
// properties.put("user", "test_admin");
// properties.put("password", "x-pack-test-password"); return properties; }
public static void main(String[] args) {
String address = "jdbc:es:// + elasticsearchAddress;
Properties connectionProperties = connectionProperties();
JdbcDataSource dataSource = new JdbcDataSource(); dataSource.setUrl(address); dataSource.setProperties(connectionProperties);
try {
Connection connection = dataSource.getConnection();
System.out.println(connection);
Statement statement = connection.createStatement();
ResultSet results = statement.executeQuery( "SELECT * FROM bank ");
while(results.next()){
System.out.println(results.getString("firstname"));
}
} catch (SQLException e) { e.printStackTrace(); } } }
遇到如下错误:
请问大神们该如何解决,尝试过官网的两种连接方式不行。也手动导入过lucene-code-5.2.1.jar包,接着提示java.lang.NoSuchFieldError: LUCENE_5_3_1的错误。
public class ESJdbcTest {
static String driver = "org.elasticsearch.xpack.sql.jdbc.jdbc.JdbcDriver";
static String elasticsearchAddress = "127.0.0.1:9200";
public static Properties connectionProperties(){
Properties properties = new Properties();
// properties.put("user", "test_admin");
// properties.put("password", "x-pack-test-password"); return properties; }
public static void main(String[] args) {
String address = "jdbc:es:// + elasticsearchAddress;
Properties connectionProperties = connectionProperties();
JdbcDataSource dataSource = new JdbcDataSource(); dataSource.setUrl(address); dataSource.setProperties(connectionProperties);
try {
Connection connection = dataSource.getConnection();
System.out.println(connection);
Statement statement = connection.createStatement();
ResultSet results = statement.executeQuery( "SELECT * FROM bank ");
while(results.next()){
System.out.println(results.getString("firstname"));
}
} catch (SQLException e) { e.printStackTrace(); } } }
遇到如下错误:
请问大神们该如何解决,尝试过官网的两种连接方式不行。也手动导入过lucene-code-5.2.1.jar包,接着提示java.lang.NoSuchFieldError: LUCENE_5_3_1的错误。
0 个回复