Velocity Reviews

Velocity Reviews (http://www.velocityreviews.com/forums/index.php)
-   Java (http://www.velocityreviews.com/forums/f30-java.html)
-   -   interview question on database update (http://www.velocityreviews.com/forums/t622414-interview-question-on-database-update.html)

Garg 06-26-2008 04:57 PM

interview question on database update
 
Hi,

I want for an interview today. They asked me many questions and i
given correct answer except two (regarding Java)

1. if I need to update a database with 1000 records and how should i
proceed and how can i use transaction save point in this.

2. i am having a class with two constructor one is default and one is
with some parameters. How can i convert this in the singleton class.

Answer :

1. first part: I will preferable go for the prepared statement for
this with four loop
1. Second part : it's possible only if you use try catch block in the
for loop.

2. make both the constructor private.

Please tell me how should i go about if i need to implement these
conditions.

Thanks in advance
Garg

John B. Matthews 06-26-2008 09:12 PM

Re: interview question on database update
 
In article
<a5f71a73-5cc1-47cb-a528-02a9b143de6c@a9g2000prl.googlegroups.com>,
Garg <sendtogarg@gmail.com> wrote:

> Hi,
>
> I w[e]nt for an interview today. They asked me many questions and
> [I gave] correct answer[s,] except two regarding Java[.]
>
> 1. [I]f I need to update a database with 1000 records, how should [I]
> proceed and how can [I] use [a] transaction savepoint in this.
>
> 2. [I have] a class with two constructor[s,] one is default and one is
> with parameters. How can [I] convert this [to a] singleton class[?]
>
> Answer :
>
> 1. [F]irst part: I will [use a] prepared statement for
> this with [a for] loop[.]


No, the answer lies in Connection.

> 1. Second part : it's possible only if you use [a] try catch block in
> the for loop.


This suggests a fundamental misunderstanding of transactions.

> 2. [M]ake both the constructor[s] private.


This is only one step. Refer to any decent textbook. Start here, paying
close attention to the references:

<http://en.wikipedia.org/wiki/Singleton_pattern>

> Please tell me how should [I] go about implement[ing] these
> conditions.


[A NewYorker] is approached in the street near Carnegie Hall, and asked,
"Can you tell me, how do I get to Carnegie Hall?" He replies, "Practice,
practice, practice." :-)

> Thanks in advance
> Garg


--
John B. Matthews
trashgod at gmail dot com
home dot woh dot rr dot com slash jbmatthews

Garg 06-27-2008 02:32 AM

Re: interview question on database update
 

> No, the answer lies in Connection.
>

I am not getting this. I have data in Arraylist so how connection will
help in this.

Garg

Garg 06-28-2008 04:27 AM

Re: interview question on database update
 
The picture is clear in my mind and My question was if i need to
update the 1000 records in a database and these records are with me in
a arraylist. Then suggest me a way so that i can update these records
in the database.

Should I use preparedStatement for this?

This was my question.

and As John said the answer lies in connection then what my
understanding says is that that first we make a connection to the
database and then we make a statement (simple statement, prepared
statement or callable statement) and then we execute these statements.

there are different types of statement for different purposes but i am
not able to understand which type of connection will help in updating
1000 records in the database.

Tarun

Arved Sandstrom 06-28-2008 10:31 AM

Re: interview question on database update
 
"Garg" <sendtogarg@gmail.com> wrote in message
news:fc8973bc-b83b-4839-8a1f-14af38163825@v1g2000pra.googlegroups.com...
> The picture is clear in my mind and My question was if i need to
> update the 1000 records in a database and these records are with me in
> a arraylist. Then suggest me a way so that i can update these records
> in the database.
>
> Should I use preparedStatement for this?
>
> This was my question.
>
> and As John said the answer lies in connection then what my
> understanding says is that that first we make a connection to the
> database and then we make a statement (simple statement, prepared
> statement or callable statement) and then we execute these statements.
>
> there are different types of statement for different purposes but i am
> not able to understand which type of connection will help in updating
> 1000 records in the database.
>
> Tarun


Here's a question that arises. Is it important to you that all of the
updates either succeed or fail? Are the updates related to one another?

Also, what's your sense of what was meant by the number 1000? Is it being
used just to mean "big"? As in, they could have also said 100,000 or
1,000,000? The size of update will also determine what you do in real life.

AHS



John B. Matthews 06-28-2008 03:27 PM

Re: interview question on database update
 
In article
<fc8973bc-b83b-4839-8a1f-14af38163825@v1g2000pra.googlegroups.com>,
Garg <sendtogarg@gmail.com> wrote:

> The picture is clear in my mind and My question was if i need to
> update the 1000 records in a database and these records are with me in
> a arraylist. Then suggest me a way so that i can update these records
> in the database.
>
> Should I use preparedStatement for this?
>
> This was my question.


No. Your [edited] question was

> 1. [I]f I need to update a database with 1000 records, how should [I]
> proceed and how can [I] use [a] transaction savepoint in this.


And your [edited, incorrect] answered was

> 1. [F]irst part: I will [use a] prepared statement for
> this with [a for] loop[.]


> and As John said the answer lies in connection then what my
> understanding says is that that first we make a connection to the
> database and then we make a statement [...]


Before you prepare any statements, you must do your homework: Read the
documentation for java.sql.Connection, searching for keywords from your
_actual_ question. If you skip pronouns, articles, conjunctions and
prepositions, the search will take less time than it did to compose this
response. When you have done this, you will understand why your answer
was wrong, and you will have learned a method of finding the right
answer.

--
John B. Matthews
trashgod at gmail dot com
home dot woh dot rr dot com slash jbmatthews

Garg 06-30-2008 11:13 AM

Re: interview question on database update
 
Thanks for your reply ..

but these replies are discouraging me.

John B. Matthews 06-30-2008 05:45 PM

Re: interview question on database update
 
In article
<8f9f0670-f975-4546-b388-69882c20c54f@h1g2000prh.googlegroups.com>,
Garg <sendtogarg@gmail.com> wrote:

> Thanks for your reply ..
>
> but these replies are discouraging me.


After you have searched the java.sql.Connection documentation for the
keywords from your question, your spirits will lift.

Here was the question:

> 1. [I]f I need to update a database with 1000 records, how should [I]
> proceed and how can [I] use [a] transaction savepoint in this.


Skipping pronouns, articles, conjunctions and prepositions, the list is
short: update, database, proceed, transaction, savepoint. Some words
aren't present; some are so general as to be useless, so you move on.

You will surely have questions about what you find.

--
John B. Matthews
trashgod at gmail dot com
home dot woh dot rr dot com slash jbmatthews

thufir 07-05-2008 06:05 AM

Re: interview question on database update
 
On Thu, 26 Jun 2008 09:57:03 -0700, Garg wrote:


> 2. make both the constructor private.



I'm just not seeing how or why a Singleton could or would use a
constructor with parameters.


-Thufir

Kevin McMurtrie 07-05-2008 09:47 AM

Re: interview question on database update
 
In article <6bEbk.56507$Jx.7968@pd7urf1no>,
thufir <hawat.thufir@gmail.com> wrote:

> On Thu, 26 Jun 2008 09:57:03 -0700, Garg wrote:
>
>
> > 2. make both the constructor private.

>
>
> I'm just not seeing how or why a Singleton could or would use a
> constructor with parameters.
>
>
> -Thufir


Exactly. It sounds like a trick question about anti-patterns. I think
the interviewer was trying to encourage a discussion about when a
singleton pattern is appropriate. "Make both constructors private" is
an incomplete answer that will cause somebody to fail their next
interview too :)

--
I will not see your reply if you use Google.


All times are GMT. The time now is 08:05 AM.

Powered by vBulletin®. Copyright ©2000 - 2014, vBulletin Solutions, Inc.
SEO by vBSEO ©2010, Crawlability, Inc.