import java.sql.*;
import java.util.Properties;
public class Main {
public static void main(String[] args) {
try {
Class.forName("org.elasticsearch.xpack.sql.jdbc.jdbc.JdbcDriver");
} catch (ClassNotFoundException e) {
e.printStackTrace();
return;
}
String address = "jdbc:es://http://YOUR_ES_VIP:9200";
Properties properties = new Properties();
properties.put("user", "elastic");
properties.put("password", "YOUR_PASS");
Connection connection = null;
try {
connection = DriverManager.getConnection(address, properties);
Statement statement = connection.createStatement();
ResultSet results = statement.executeQuery("select FlightNum from kibana_sample_data_flights limit 10");
while (results.next()) {
System.out.println(results.getString(1));
}
} catch (Exception e) {
e.printStackTrace();
} finally {
try {
if (connection != null && !connection.isClosed()) {
connection.close();
}
} catch (SQLException e) {
e.printStackTrace();
}
}
}
}
Was this page helpful?