If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Data Access, Manipulation & Batch Languages > JAVA > ResultSetMetaData Problem - TableName is not showing

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 07-31-06, 09:58
dinesh g dinesh g is offline
Registered User
 
Join Date: Jul 2006
Posts: 6
ResultSetMetaData Problem - TableName is not showing

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
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On