gpt4 book ai didi

java - 如何在不知道列类型的情况下获取列的值

转载 作者:可可西里 更新时间:2023-11-01 06:40:39 24 4
gpt4 key购买 nike

我正在根据用户选择要在结果中显示的字段动态创建查询。问题是,当要从数据库中检索数据时,我通常使用 getXXX() 方法来检索适当的类型。但在这种情况下,我不知道合适的类型是什么,因为列是随机选择的。

有什么方法可以在不指定数据类型 XXX 的情况下获取字符串格式的数据?我正在使用 MySQL 和 Servlet。

最佳答案

您可以使用通用的 getObject方法:

Gets the value of the designated column in the current row of this ResultSet object as an Object in the Java programming language.

This method will return the value of the given column as a Java object. The type of the Java object will be the default Java object type corresponding to the column's SQL type, following the mapping for built-in types specified in the JDBC specification. If the value is an SQL NULL, the driver returns a Java null.

关于java - 如何在不知道列类型的情况下获取列的值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15310549/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com