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);

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">
<% for (int i=1; i<numColumns+1; i++) {
<th><% out.write(rsmd1.getColumnName(i));%></th>
<%} %>

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




Thankz to all of U