Open ruixuel opened 6 years ago
Just use reflection to get it.
Field field = sqlRowStream.getClass().getDeclaredField("metaData"); field.setAccessible(true); ResultSetMetaData metaData = (ResultSetMetaData) field.get(sqlRowStream);
int cols = metaData.getColumnCount(); for (int i = 1; i <= cols; i++) { // metaData.getColumnTypeName(i) }
Version
Context
Hi, I am wondering if it is possible to add column type in io.vertx.ext.sql.ResultSet. I need column data type from java.sql.ResultSetMetaData and convert the query result to apache arrow according to the column data type.
In io.vertx.ext.jdbc.impl.actions.JDBCStatementHelper.java, io.vertx.ext.sql.ResultSet already get the column names from ResultSetMetaData. So it would be nice if ColumnType could also be added to ResultSet. ColumnType can be get from ResultSetMetaData by getColumnType(int) method.(https://docs.oracle.com/javase/7/docs/api/java/sql/ResultSetMetaData.html#getColumnType(int))
public io.vertx.ext.sql.ResultSet asList(ResultSet rs) throws SQLException { List columnNames = new ArrayList<>();
ResultSetMetaData metaData = rs.getMetaData();
int cols = metaData.getColumnCount();
for (int i = 1; i <= cols; i++) {
columnNames.add(metaData.getColumnLabel(i));
//Add column types here?
}
.....
return new io.vertx.ext.sql.ResultSet(columnNames, results, null);
}
If it is not possible to do that, is there any way that I can do asynchronous sql query and get the column type from the query result?
Thank you!