• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

how to fetch data from resultset containing result of two queries

 
jai hanuman
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
please help me,

i am executing a sql query " select * from emp select * from customer ".
in ms sql server 2005's query browser it is showing result from both tables separably but while executing the same query
using prepared statement in java it is not showing data of emp table only.

so anybody please tell me how to solve this problem.
 
Paul Sturrock
Bartender
Posts: 10336
Eclipse IDE Hibernate Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Executing the same query? You've got two queries; how did you combine them into one?
 
jai hanuman
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Paul Sturrock wrote:Executing the same query? You've got two queries; how did you combine them into one?


my problem is that the query "select * from emp select * from customer" is not giving error while executing through
preparestatement.executeQuery();

it is fetching data from emp table only.
and it is returning empty string while fetching table name
 
Campbell Ritchie
Sheriff
Posts: 51468
87
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
"select * from emp select * from customer"? Is that a query? Will it actually compile? Can you say select twice?
 
krishna bala
Ranch Hand
Posts: 62
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
select * from emp select * from customer
this query will give ORA-00933: SQL command not properly ended found exception
how it is working for you ?
 
jai hanuman
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
krishna bala wrote:
select * from emp select * from customer
this query will give ORA-00933: SQL command not properly ended found exception
how it is working for you ?



i think this will give error in oracle database but i am using ms sql server 2005 which is compiling query properly and giving result of both the queries.
 
Paul Sturrock
Bartender
Posts: 10336
Eclipse IDE Hibernate Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Query Analyzer is making it appear that these two queries can be run as one. On its own its not valid SQL. If you want to run two queries in JDBC, run them as two PreparedStatements.
 
jai hanuman
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Paul Sturrock wrote:Query Analyzer is making it appear that these two queries can be run as one. On its own its not valid SQL. If you want to run two queries in JDBC, run them as two PreparedStatements.


the problem with this is the query is dynamic and we don't know that it is containing how many queries
so how will i find out the number of queries.
 
Paul Sturrock
Bartender
Posts: 10336
Eclipse IDE Hibernate Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
So how do you get the SQL for these queries? Can you explain a bit more about your logic?
 
jai hanuman
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Paul Sturrock wrote:So how do you get the SQL for these queries? Can you explain a bit more about your logic?


i am developing an online sql query analyzer in which client will test his queries by writing queries into a textarea
and accordingly the result will be shown in tabular format to the user,


i am fetching query by using request.getParameter ("query");
and executing the query using praparestatement.executeQuery(query)
 
Campbell Ritchie
Sheriff
Posts: 51468
87
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Please don't use orange writing; it is difficult to read.
 
Paul Sturrock
Bartender
Posts: 10336
Eclipse IDE Hibernate Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
OK, then you will need to perform the same logic Query Analyzer does whereby it parses the Transact SQL before running it. The easiest way to do this is to require proper statement ends (batch seperator in SQL Server speak). If you can't do that then you will need to parse the input with a Transact SQL grammar and break it down into seperate statements.
 
jai hanuman
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Paul Sturrock wrote:OK, then you will need to perform the same logic Query Analyzer does whereby it parses the Transact SQL before running it. The easiest way to do this is to require proper statement ends (batch seperator in SQL Server speak). If you can't do that then you will need to parse the input with a Transact SQL grammar and break it down into seperate statements.



please tell me how can i parse the input query or validate the input query.
I don't know parsing using transact sql grammar.
 
Paul Sturrock
Bartender
Posts: 10336
Eclipse IDE Hibernate Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Well, you could go looking for an existing grammar and use an existing parser technology like Antrl. Unfortunately, I don't know of any TSQL grammars out there, so you may have to define you own.

Not a trivial task, I'm afraid.

 
Campbell Ritchie
Sheriff
Posts: 51468
87
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Please don't quote the whole of the preceding post; it makes the thread much slower to read.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic