Storing different parameter types in a single table
I have a Java class representing an event that contains some data, and also a list of 'parameters' of varying types, for lack of a better word. I want to persist this into a database, and I'm confused as to the best approach.
edited to try to clarify my ramblings:
Depending on the type of 'event', it could have parameters like hostname, port, date, service name, time of message, digest of a certificate (byte array), etc.
I guess the closest parallel would be like storing a printf format string and parameters (a开发者_如何学Clthough that's not what I'm doing). Storing the format string is easy, but storing the parameters is tricky, since I'd need to get them back to their original types when retrieved.
I'm trying to figure out a way to store the parameters which will be of varying types. Should I encode them as some string format and stuff them into a varchar(), then decode when I retrieve the parameters for the event?
Storing everything as varchar / string is a bad idea in my humble opinion. If you need to store various data types in a database store them with the correct types. That way your presentation layer can deal with formatting.
精彩评论