Long time no see!
I'm in the process of creating a web application and wanted to speed up the process of updating Prepared Statements when new fields are added to the XSD that generates my JavaBean class and corresponding database table. Here's the process in order:
Once the class has been rewritten with the updated fields and corresponding getter/setter methods, it's "available" to be set.
However, the issue still stands that I have to go into my DAO class for the class and update the resultSet and 'get' the field.
String foo = resultSet.getString("TABLENAME_foo");
Then, I have to set the class instance for the method:
instanceObj.setFoo(foo);
Any ideas on how I'd go about automating this process? This is a relatively simple thing to update, but the point is, I want as much automation as possible.
You can generate the DAO class out of the XSD files. Then you can get/set the values for each field defined there. An alternative is to create a generic method in the DAO which either uses introspection to find out about the properties or analyzing the XSD and use those infos to set the properties properly.
You can use ResultSetMetaData
from ResultSet
ResultSetMetaData metadata = resultSet.getMetaData();
int columnCount = metadata.getColumnCount();
for (int i=1; i<=columnCount; i++)
{
String columnName = metadata.getColumnName(i);
}
Then use Reflection to set the instance.
But in this case, the instance's field name has to be same as DB column name. Or you can use SELECT TABLENAME_foo as fieldName FROM ***
to work around.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.