Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 828
  • Last Modified:

Java SQL execute Update

hi all,

        I have a little confusion in a answering an objective question, I can across in a test regarding executeUpdate.

        according to API, executeUpdate returns either a 0 or the row count...
        But in the possible options, I am not seeing status code 0 at all.

     
0
aman0711
Asked:
aman0711
  • 10
  • 5
  • 4
2 Solutions
 
arevuriCommented:
i am not sure what do you mean by possible option. But executeUpdate will return 0 if no records are upated with your query stmt. If there are any records that are updated will give count of records that are updated.
0
 
kadabaCommented:
hi aman,

what options are there?
executeUpdate public int executeUpdate(String sql)
                  throws SQLException Executes the given SQL statement, which may be an INSERT,   UPDATE, or DELETE statement or an  SQL statement that returns nothing, such as an SQL DDL statement.
 Parameters:sql - an SQL INSERT, UPDATE or  DELETE statement or an SQL statement that returns nothing Returns:either the row count for INSERT, UPDATE  or DELETE statements, or 0 for SQL statements   that return nothing Throws: SQLException - if a database access error occurs or the given             SQL statement produces a ResultSet object

0
 
aman0711Author Commented:
Hey Kadaba, arevuri,
 
              Thanks for the reply :)

Here are the options:



executeUpdate should be used when a SQL does not return results.

what value does executeUpdate return? 
Choice 1 
A result set with one entry specifying the number of altered rows 
Choice 2 
The number of rows altered 
Choice 3 
The size of the result set 
Choice 4 
An integer status code indicating the success or failure of the SQL statement 
Choice 5 
The number of rows in the altered table

Open in new window

0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
aman0711Author Commented:
I guess choice 4 in this scenario?
0
 
kadabaCommented:
Choice 2
The number of rows altered
0
 
aman0711Author Commented:
Hi Kadaba,

         I am confused here, in the top statement its said that statement isnt returning any results. so which means a status code of  0. isnt it?

 I have another question for you, which I cant find answer for :)
0
 
kadabaCommented:
Choice 1
A result set with one entry specifying the number of altered rows -- throws SQL exception if it does
Choice 2
The number of rows altered -- true
Choice 3
The size of the result set -- not applicable
Choice 4
An integer status code indicating the success or failure of the SQL statement -- the success itself is governed by return code 0 if DDL statement else no of rows altered if DML statements
Choice 5
The number of rows in the altered table - if an alter table query is executed then return code would be 0.

the options me too :P, wait for arevuri's or anyone else's view :)
0
 
aman0711Author Commented:
hehe no worries :-)
   
Ok heres another tricky one :)

 What Java technology do you use in JSP to map HttpRequest parameters to properties in JavaBeans?
0
 
aman0711Author Commented:
Kadaba,

     Check your email :)
0
 
kadabaCommented:
looking at it again...

Choice 1 is wrong since an int value is returned to be clear.

So 2 is correct

choice 3 is wrong

4 - not correct

5 - not correct

I will answer the other one bit later, time for dinner ;)
0
 
arevuriCommented:
executeUpdate should be used in one of thw folllowing cases

1. For INSERT, UPDATE or DELETE DML Operation SQL queries. In this case this method retuns number of records affected in the database.

2.it can also be used to execute DDL queries for example, CREATE, ALTER, DROP etc. In this case this method always retuns zero for success or throws SQLException for any failures.
0
 
arevuriCommented:
For other questin on http parameters, use servlets or JSP to read values using http request bject parameter values and assign them to your java beans or try custom tag libs technology
0
 
aman0711Author Commented:
Hey arevuri, let me show u the options for second one
0
 
aman0711Author Commented:
Here are the options for 2nd question:

Reflection and inheritance, JSP Container, Polymorphism, Introspection and reflection,
 JNI
0
 
arevuriCommented:
reflections are vey costly in terms of performance
0
 
aman0711Author Commented:
So what would be the option for this arevuri?
0
 
arevuriCommented:
you do not need any new technology for this. You can directly get values of http parameters using implicit objects of JSP (like request.getParameter("")) and set it to your bean. If your page is dynamic, you do not know the param names and want to create new java bean classes dynamically, then reflections are only the way
0
 
aman0711Author Commented:
Thanks arevuri,

 so I guess I will pick:

Introspection and reflection


0
 
aman0711Author Commented:
Thanks folks :)
0

Featured Post

Become an Android App Developer

Ready to kick start your career in 2018? Learn how to build an Android app in January’s Course of the Month and open the door to new opportunities.

  • 10
  • 5
  • 4
Tackle projects and never again get stuck behind a technical roadblock.
Join Now