I am developing one application in jsp where user can enter any number of queries and thet will be executed and will show the output in another page.

i am using the ResultSetMetaData to get the tablename and also the column name for the query entered by the user.

If the user enters two queries,First time getTableName() method will return the correct tablename and for the second it will show tablename as "from".

Here is the code.

st = theConnection.createStatement();
String str="";
int queryLength = query.length();
String tableName="";
ResultSetMetaData rsmd1;
ResultSet rs1;
for(int j=0;j<queryLength;j++)
{
str +=query.charAt(j);
if(query.charAt(j)==';')
{
if(str.indexOf("temp")==-1)
{

rs1 =st.executeQuery(str);
rsmd1 = rs1.getMetaData();
numColumns = rsmd1.getColumnCount();
tableName = rsmd1.getTableName(numColumns-1);

out.write("Table Name1: "+tableName);
%>

<table width="75%" border="1">
<tr>
<% for (int i=1; i<numColumns+1; i++) {
%>
<th><% out.write(rsmd1.getColumnName(i));%></th>
<%} %>
</tr>

<%
ResultSet rs2 = st.executeQuery(str);
while(rs2.next()){ %>
<tr>
<% for (int i=1; i<numColumns+1; i++){ %>
<td>
<% out.write(rs2.getString(i)); %> </td>
<% } %>
</tr>
<%} //rs1.close();
%>
</table>
<br><br>


<%}
else
st.executeUpdate(str);

str="";
}

}




Thankz to all of U