You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@hive.apache.org by Bhavesh Shah <bh...@gmail.com> on 2012/03/16 06:47:54 UTC

Problem related to Hive using JDBC

Hi,
I am trying to implement a task in Hive like Stored Procedure in SQL.
In SQL, when we write cursor, first we execute select query and then
fetching the records we perform some actions.

Likely I have fired a select query as actions in Hive.
sql="select a,c,b from tbl_name";
res=stmt.executeQuery();    -----------> CONTAINS 30 RECORDS
while(res.next())
{
     sql="insert into tabl2..... ";
     rs1=stmt.executeQuery();
     like wise many queries are there.....

.
.
.
..
}

As my select query contans 30 records but when I execute it   my
while(res.next()) execute only once.
I didn't get any kind of errors/exceptions

But instead of queries I just try to display field to check whether it is
fetching or not
then it is working fine..  (while loop contains only System.out.println
statements)

sql="select * from tbl_name";
res=stmt.executeQuery(sql);

while(res.next())
{
   S.O.P.("fields : "+res.getString(0));
}

Why it is happening I am not getting. Is anything I am doing wrong?






-- 
Regards,
Bhavesh Shah

Re: Problem related to Hive using JDBC

Posted by Bhavesh Shah <bh...@gmail.com>.
Thanks Shashwat for your reply.

According your reply, I am getting all column data using
res.getInt/getString for 30 times.
Actually my doubt is in:

sql="select a,c,b from tbl_name";
res=stmt.executeQuery();    -----------> CONTAINS 30 RECORDS
while(res.next())
{
     sql="select d,e,f, from t1";
     rs1=stmt.executeQuery();
     like wise many queries are there.....

.
.
.
..
}
This above syntax is execute only once instead of 30 times.
Thats what my doubt is?




On Sat, Mar 17, 2012 at 4:26 PM, shashwat shriparv <
dwivedishashwat@gmail.com> wrote:

>  S.O.P.("fields : "+res.getString(0));
> according type of your fields you can acc more res.getint(1)
> res.getString(2) like this up to 30 so this will give all the columns you
> needed.
>
>
>
> On Fri, Mar 16, 2012 at 11:17 AM, Bhavesh Shah <bh...@gmail.com>wrote:
>
>>
>> Hi,
>> I am trying to implement a task in Hive like Stored Procedure in SQL.
>> In SQL, when we write cursor, first we execute select query and then
>> fetching the records we perform some actions.
>>
>> Likely I have fired a select query as actions in Hive.
>> sql="select a,c,b from tbl_name";
>> res=stmt.executeQuery();    -----------> CONTAINS 30 RECORDS
>> while(res.next())
>> {
>>      sql="insert into tabl2..... ";
>>      rs1=stmt.executeQuery();
>>      like wise many queries are there.....
>>
>> .
>> .
>> .
>> ..
>> }
>>
>> As my select query contans 30 records but when I execute it   my
>> while(res.next()) execute only once.
>> I didn't get any kind of errors/exceptions
>>
>> But instead of queries I just try to display field to check whether it is
>> fetching or not
>> then it is working fine..  (while loop contains only System.out.println
>> statements)
>>
>> sql="select * from tbl_name";
>> res=stmt.executeQuery(sql);
>>
>> while(res.next())
>> {
>>    S.O.P.("fields : "+res.getString(0));
>> }
>>
>> Why it is happening I am not getting. Is anything I am doing wrong?
>>
>>
>>
>>
>>
>>
>> --
>> Regards,
>> Bhavesh Shah
>>
>>
>
>
> --
> Shashwat Shriparv
>
> +91-9663531241
> +91-990059620
>
>


-- 
Regards,
Bhavesh Shah

Re: Problem related to Hive using JDBC

Posted by shashwat shriparv <dw...@gmail.com>.
 S.O.P.("fields : "+res.getString(0));
according type of your fields you can acc more res.getint(1)
res.getString(2) like this up to 30 so this will give all the columns you
needed.



On Fri, Mar 16, 2012 at 11:17 AM, Bhavesh Shah <bh...@gmail.com>wrote:

>
> Hi,
> I am trying to implement a task in Hive like Stored Procedure in SQL.
> In SQL, when we write cursor, first we execute select query and then
> fetching the records we perform some actions.
>
> Likely I have fired a select query as actions in Hive.
> sql="select a,c,b from tbl_name";
> res=stmt.executeQuery();    -----------> CONTAINS 30 RECORDS
> while(res.next())
> {
>      sql="insert into tabl2..... ";
>      rs1=stmt.executeQuery();
>      like wise many queries are there.....
>
> .
> .
> .
> ..
> }
>
> As my select query contans 30 records but when I execute it   my
> while(res.next()) execute only once.
> I didn't get any kind of errors/exceptions
>
> But instead of queries I just try to display field to check whether it is
> fetching or not
> then it is working fine..  (while loop contains only System.out.println
> statements)
>
> sql="select * from tbl_name";
> res=stmt.executeQuery(sql);
>
> while(res.next())
> {
>    S.O.P.("fields : "+res.getString(0));
> }
>
> Why it is happening I am not getting. Is anything I am doing wrong?
>
>
>
>
>
>
> --
> Regards,
> Bhavesh Shah
>
>


-- 
Shashwat Shriparv

+91-9663531241
+91-990059620