• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Tim Cooke
  • Devaka Cooray
Sheriffs:
  • Liutauras Vilda
  • paul wheaton
  • Rob Spoor
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Piet Souris
  • Mikalai Zaikin
Bartenders:
  • Carey Brown
  • Roland Mueller

how to fetch data from resultset containing result of two queries

 
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Bartender
Posts: 10336
Hibernate Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Marshal
Posts: 79699
381
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
"select * from emp select * from customer"? Is that a query? Will it actually compile? Can you say select twice?
 
Ranch Hand
Posts: 62
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Hibernate Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Hibernate Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Marshal
Posts: 79699
381
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Please don't use orange writing; it is difficult to read.
 
Paul Sturrock
Bartender
Posts: 10336
Hibernate Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Hibernate Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Marshal
Posts: 79699
381
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Please don't quote the whole of the preceding post; it makes the thread much slower to read.
 
I carry this gun in case a vending machine doesn't give me my fritos. This gun and this tiny ad:
We need your help - Coderanch server fundraiser
https://coderanch.com/wiki/782867/Coderanch-server-fundraiser
reply
    Bookmark Topic Watch Topic
  • New Topic