- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
在 clojure/java jdbc 中,我了解到使用 getMetaData 我可以返回大量关于通过 jdbc 连接的数据库的有趣信息。这可以根据目录、架构和表名进行过滤。
(defn get-db-metadata
[db-spec ]
(with-connection (get-db-connection-map db-spec)
; get columns returs the following:
; TABLE_CAT String => table catalog (may be null)
; TABLE_SCHEM String => table schema (may be null)
; TABLE_NAME String => table name
; COLUMN_NAME String => column name
; DATA_TYPE int => SQL type from java.sql.Types
; TYPE_NAME String => Data source dependent type name, for a UDT the type name is fully qualified
; COLUMN_SIZE int => column size. For char or date types this is the maximum number of characters, for numeric or decimal types this is precision.
; BUFFER_LENGTH => not used.
; DECIMAL_DIGITS int => the number of fractional digits
; NUM_PREC_RADIX int => Radix (typically either 10 or 2)
; NULLABLE int => is NULL allowed.
; columnNoNulls => might not allow NULL values
; columnNullable => definitely allows NULL values
; columnNullableUnknown => nullability unknown
; REMARKS String => comment describing column (may be null)
; COLUMN_DEF String => default value (may be null)
; SQL_DATA_TYPE int => unused
; SQL_DATETIME_SUB int => unused
; CHAR_OCTET_LENGTH int => for char types the maximum number of bytes in the column
; ORDINAL_POSITION int => index of column in table (starting at 1)
; IS_NULLABLE String => "NO" means column definitely does not allow NULL values; "YES" means the column might allow NULL values. An empty string means nobody knows.
; SCOPE_CATLOG String => catalog of table that is the scope of a reference attribute (null if DATA_TYPE isn't REF)
; SCOPE_SCHEMA String => schema of table that is the scope of a reference attribute (null if the DATA_TYPE isn't REF)
; SCOPE_TABLE String => table name that this the scope of a reference attribure (null if the DATA_TYPE isn't REF)
; SOURCE_DATA_TYPE short => source type of a distinct type or user-generated Ref type, SQL type from java.sql.Types (null if DATA_TYPE isn't DISTINCT or user-generated REF)
(into #{}
(map #(str (% :table_name) "." (% :column_name) "\n")
(resultset-seq (->
(connection)
(.getMetaData)
; Params in are catalog, schemapattern, tablenamepattern
;(.getColumns "stuff" "public" nil "%")
(.getColumns "db_catalog" "schema_name" "some_table" "%")
)
)
)
)
)
)
我感兴趣的不是数据库中每个表的信息,而是特定查询 返回的结果集。在这一点上,我的具体需求是知道检索到的特定列的最大长度,例如以固定宽度格式打印到屏幕。
到目前为止我考虑过的(我确定不理想):
尝试解析入站 sql 语句以找出哪些表正在查询,然后获取这些表的元数据具体来说。结果会很复杂带有函数或公用表表达式等的 select 语句的一部分。我认为它很快就会变得困惑(而且不准确)。
创建一个基于 入站查询...然后我可以获取此 View 上的元数据。这个 但是,如果我只有一个只读连接到 我正在使用的数据库。通常情况下,我相信我正在尝试做的事情。
获取结果,然后为返回的每一列查找 值的最大长度,然后创建我的固定宽度网格 因此。如果我看大的话,这就不太好了 结果集......
是否有更好的方法来确定我从查询返回的所有内容的类型?其他程序如何做到这一点?似乎我应该能够从我在这里以某种方式发出查询请求时获取元数据:
(defn fetch-results
"Treat lazy result sets in whole for returning a database query"
[db-spec query]
(with-connection
(get-db-connection-map db-spec)
(with-query-results res query
; (get the medata here somehow for columns returned ????)
(doall res))
)
)
提前致谢。
最佳答案
你可以在 scala 中这样做,也许这可以帮助你:
var stmt: PreparedStatement = null
var rs: ResultSetMetaData = null
try {
stmt = conn.prepareStatement(query)
rs = stmt.getMetaData()
} finally {
cleanup(stmt)
}
}
关于用于特定查询的 jdbc getMetaData,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16963550/
在 clojure/java jdbc 中,我了解到使用 getMetaData 我可以返回大量关于通过 jdbc 连接的数据库的有趣信息。这可以根据目录、架构和表名进行过滤。 (defn get-d
我一直在尝试将 Ucanacces 与 getMetaData() 一起使用,但我遇到了一些问题,当我尝试显示信息时出现此错误: Error de SQLException:net.ucanacces
我需要使用复制事件将文件从文件夹复制到 Azure BLOB 存储,并且此复制事件应仅当文件存在于特定文件夹中时运行。我使用 GETMETADATA 事件来查看文件是否存在,但我需要配置此输出,以便在
我正在使用一个简单的应用程序来帮助学习 Apache.Derby 数据库并在 Eclipse 中工作。以下代码运行正常,但 conn.getMetaData() 不会返回任何与表相关的有意义的内容 -
在 ColdFusion 10 中的组件上调用 getMetaData() 似乎会随机抛出内部 NullPointerException。虽然此异常既不会暴露也不会影响实际请求(因此对我们的应用程序本
我正在使用 confluent golang对于我的卡夫卡客户。我使用 AdminClient 在 kafka 集群中创建/删除/获取主题。这是我初始化 AdminClient 的代码 adminCl
我开始使用 typeorm。我创建了一些实体: @Table() export class User { @PrimaryColumn() name: string; @Column() passwo
我需要从下面的代码返回一个可滚动的结果集: ResultSet columnMetaData = connection.getMetaData().getColumns(null, null, "my
我正在使用 JDBC 驱动程序连接到不同的数据库类型。我的数据库的用户仅具有目录的查看权限。它适用于 hive/teradata,但不适用于 Oracle。 使用 Oracle,我可以检索架构,但不能
有没有办法将从 getExportedKeys() 返回的 ResultSet 对象设置为 TYPE_SCROLL_SENSITIVE?我知道准备好的语句可以初始化为此值,但是从其他方法(例如 get
我正在尝试获取当前在我的应用程序中登录的当前 firebase 用户的创建日期。所以我使用下面的代码: FirebaseAuth.getInstance().getCurrentUser().getM
我一直在尝试从 Firebase 存储中获取图像文件的元数据 (md5hash),并检查它是否与用户手机上图像文件的 md5hash 不相等。问题是即使哈希值相同,我得到的结果也是不同的。 这是我尝试
本文整理了Java中org.geoserver.wms.WMSInfoImpl.getMetadata()方法的一些代码示例,展示了WMSInfoImpl.getMetadata()的具体用法。这些代
我正在尝试使用 this 在 Android 中制作一个音频应用程序视频作为指南,我在使用音频的元数据创建通知时遇到了问题。 这是我用来从设备中提取音频文件的代码: public void loadD
这是我的 sql 查询字符串: select t.create_date, concat('+', t.points) as points, case t.obtain
我在 plunker 中使用了这个 (Reflect.getMetadata('annotations',AppComponent)[0].template); 它工作正常 http://plnkr.
我想使用 Reflect 来获取我的组件的模板,但我收到了这个错误 console.log(Reflect.getMetadata('annotations',SectionsTemplateC
我在测试时发现了这个错误 https://github.com/ztytotoro/rxjs-extension/blob/master/src/decorators.ts#L20 export co
我正在处理一个用例,我想将加载到 Azure 数据库中的所有文件夹名称加载到不同的“控制”表中,但在正确使用 GetMetadata 事件时遇到问题。 此用例的目的是跳过所有旧文件夹(已加载),只关注
getMetaData() 或 getString() 函数不监听我的 SQL 查询中给出的别名。 SQL 查询成功执行。 这是我的查询的一部分:SELECT o.id as o_id, o.pack
我是一名优秀的程序员,十分优秀!