Output database in html [message #163453] |
Thu, 16 March 2006 15:27 |
rayhab
Messages: 2 Registered: March 2006
|
Junior Member |
|
|
Hi,
I am having problems with jsp and database output.
I am trying to output a table in an oracle data base to the screen.
It prints all the columns in the correct order, however when i print the rows in the table, it will put the first column in the the last position and shift everything over to the left
so lets say i have
first_name middle_name last_name
bob john smith
it will print out
first_name middle_name last_name
john smith bob
Here is the code
<sql:query var="t1">
select * from ${item.tableName}
</sql:query>
<tr>
<c:forEach var='columnName' items='${t1.columnNames}'>
<td>
<font><b>--${columnName}--</b></font>
</td>
</c:forEach>
</tr>
<tr>
<c:forEach var='item2' items='${t1.rows}'>
<tr>
<c:forEach var='colval' items='${item2}'>
<td>${colval}</td>
</c:forEach>
</tr>
</c:forEach>
any suggestions?
|
|
|
Re: Output database in html [message #163626 is a reply to message #163453] |
Fri, 17 March 2006 09:31 |
rayhab
Messages: 2 Registered: March 2006
|
Junior Member |
|
|
Let me elaborate more on how the table is created, because i think the problem lies in that area.
When the user creates a table, i have the following sql statement:
"create table ${param.tableName}(itemNum varchar(40))"
(If anyone knows how to create an empty table with no columns let me know because i think this will solve the problem)
Now once the table is create users are able to add columns to that table, the sql statement i use for that is:
"alter table ${param.tableName} add ${param.colName} varchar(40)"
Now from that lets say the user creates a table
so we have
itemnum
-------
now if they add two columns named col2 and col3 we have
itemnum col2 col3
------- ---- ----
Herse the part of the code thats printing the column from the database table
<c:forEach var='columnName' items='${t1.columnNames}'>
<td>
<font><b>--${columnName}--</b></font>
</td>
</c:forEach>
That code words find and prints the columns in the correct order
Now when the user enters data for the database table
itemnum=3
col2=4
col3=5
when it prints out it will show
itemnum col2 col3
------- ---- ----
4...... 5... 3...(without the periods of course)
Heres the part of code thats printing these rows from the database table
//t1.rows is the array of each column field in the row
<c:forEach var='item2' items='${t1.rows}'>
<tr>
//colval.value is the value of the field
<c:forEach var='colval' items='${item2}'>
<td>${colval.value}</td>
</c:forEach>
</tr>
</c:forEach>
|
|
|