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

前端之家收集整理的这篇文章主要介绍了java – 如何在不知道列类型的情况下获取列的值前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我正在基于用户选择要在结果中显示的字段动态创建查询.问题是,当从数据库中检索数据时,我通常使用getXXX()方法来检索适当的类型.但在这种情况下,我不知道适当的类型是什么,因为列是随机选择的.

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

解决方法

您可以使用通用 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.

原文链接:https://www.f2er.com/java/125393.html

猜你在找的Java相关文章