Pregunta

ie, I want to dynamically create extra columns for specific users if required from the JSP pages of my web app - is this possible, or is there another way of achieving the same thing?

¿Fue útil?

Solución

Short answer is no. Every row in a table must have the same number of columns.

If there is no applicable value for a column one typically inserts NULL (SQL NULL which is different from Java null). Alternatively you could change your data model and put the optional values in a different table, and use a join when you want to read the optional columns.

Finally, you could also represent the optional info in a Java object and serialize that into a Blob which you store in your table, but I would caution you against this approach since it prevents you form querying on the values in the Blob and you get an upgrade problem if the format of the Blob object changes.

Otros consejos

  1. Hibernate allows you to dynamically create database table provided you know rows and columns
  2. If you dont want to add that and still keep it simple and sweet use "<% scriptlet %>" codes in jsp containing Java code to create or modify table
  3. Instead of using scriplet you could use Struts / JSF/ Spring tags for cleaner code
Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top