views:

37

answers:

1

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 (although 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?

+1  A: 

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.

JonH
So, what would you suggest? Separate tables for different parameter types? The problem is that I'll have different types of data associated with the same event. I don't know what's available to preserve type information other than encoding to a 'common' format, then decoding when I retrieve it.
Shawn D.
@sdeer - Can you edit your original question and add on information to help us understand the situation at hand? To me so far you are looking at some sort of EAV (Entity Attribute Value) but for Datatypes, and it just doesn't sound right.
JonH