Google Visualization API 中的 JDBC 结果集到数据表?

发布于 2025-01-08 11:23:06 字数 802 浏览 6 评论 0原文

是否有将 JDBC ResultSet 转换为 Google Visualization 的通用方法 DataTable 对象?

似乎会有这样的东西使用 ResultSetMetaData 创建 ColumnDescription 对象,然后迭代填充行。但如果我能通过谷歌搜索找到它就好了。

由于 ResultSetMetaData 和 DataTable 都有许多特殊属性,在开始编写自定义方法之前,想要在这里仔细检查。

Is there a general method to convert a JDBC ResultSet to a Google Visualization DataTable object?

It seems like there would be such a thing that uses ResultSetMetaData to create ColumnDescription objects and then iterate populates rows. But darn if I can find it via Google search.

Since both ResultSetMetaData and DataTable have so many special properties, wanted to double check here before starting down the garden path of writing a custom method.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

荒岛晴空 2025-01-15 11:23:06

com.google.visualization.datasource.util.SqlDataSourceHelper 有两个静态方法 buildColumns() 和负责处理此问题的 buildRows()

  ...
  ResultSet rs = stmt.executeQuery(queryString);

  DataTable table = buildColumns(rs, columnIdsList);
  buildRows(table, rs);
  return table;

这些是从顶级方法 executeQuery(...) 调用的,然后调用类中的其他方法来处理各种情况翻译步骤。据说它只适用于 MySQL,但代码足够透明,可以针对其他目标数据库进行定制。

   sqlTypeToValueType(metaData.getColumnType(i));

The class com.google.visualization.datasource.util.SqlDataSourceHelper has two static methods buildColumns() and buildRows() that take care of this:

  ...
  ResultSet rs = stmt.executeQuery(queryString);

  DataTable table = buildColumns(rs, columnIdsList);
  buildRows(table, rs);
  return table;

These are called from the top method executeQuery(...) and in turn call other methods in the class, that handle the various translation steps. It's said to work only with MySQL but the code is transparent enough to customize for other target database.

   sqlTypeToValueType(metaData.getColumnType(i));
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文