NLPchina / elasticsearch-sql

Use SQL to query Elasticsearch
Apache License 2.0
7k stars 1.54k forks source link

Using elasticsearch-sql JDBC support,How to judge the resultSet record number is empty #337

Open ilevon opened 7 years ago

ilevon commented 7 years ago

Hi: Using elasticsearch-sql JDBC support, I met a problem.

String sql = buildSql(condition);
PreparedStatement ps = connection.prepareStatement(sql);
ResultSet resultSet = ps.executeQuery();

How to judge the resultSet record number is empty

while (resultSet != null && resultSet.next()){
   //do
  //Like above, even if there is no record will be entered here
}

I use the following: int record = resultSet.getMetaData().getColumnCount(); Query to record number, but record is equal to zero. And,whether to support the JDBC cursor paging?

For example:

PreparedStatement pstat = conn.prepareStatement(sql,ResultSet.TYPE_SCROLL_INSENSITIVE,ResultSet.CONCUR_READ_ONLY);
pstat.setMaxRows(startNo+maxCount-1);
ResultSet resultSet = pstat.executeQuery();
resultSet .first();
resultSet .relative(startNo-2);

Regards.

ansjsun commented 7 years ago

@allwefantasy

lishiyucn commented 6 years ago

I have the same problem,Who has solved it?