I am creating a query dynamically based on a user choosing fields to be displayed in the result. The problem is that when data is to be retrieved from the database I normally use getXXX()
methods to retrieve the appropriate type. But in this case I do not know what the appropriate type is since the columns are randomly chosen.
Is there any way that I can get data in string format without specifying the data type XXX? I am using MySQL and Servlets.
You can use the generic getObject method :
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With