Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

is this a correct way to use java.sql.Statement?

Posted on 2004-11-01
2
Medium Priority
?
190 Views
Last Modified: 2010-03-31
private void theMethod() throws java.sql.SQLException{
    int tmpAmount = -1;
    java.sql.Statement statement = connection.createStatement()

    java.sql.ResultSet rs = statement.executeQuery("SELECT amount FROM account_table WHERE num = '2' ");

    if(rs.next()){
        tmpAmount = rs.getInt("amount");
    }
    else{
        return;
    }

    if(tmpAmount > 0){
        statement.executeUpdate("DELETE FROM records WHERE account_num = '4'");
        statement.executeUpdate("DELETE FROM supplimental WHERE id = '4' ");
        statement.executeUpdate("UPDATE account_table SET amount = 0 WHERE num = '2'");
    }
    rs.close();
    statement.close();
}

Is it OK to reuse "statement" like this, or is there some other steps necessary?

Thanks,

Wallway
0
Comment
Question by:wallway
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 92

Accepted Solution

by:
objects earned 500 total points
ID: 12468519
thats fine, the only thing you have to worry about is only having one result set open on a statement at a time
0
 
LVL 13

Expert Comment

by:petmagdy
ID: 12468852
do u warry about ACID transaction? what if the second statment for example failed, do u need to rollback the whole transaction?

I think to consider Transaction management
0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Java had always been an easily readable and understandable language.  Some relatively recent changes in the language seem to be changing this pretty fast, and anyone that had not seen any Java code for the last 5 years will possibly have issues unde…
Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
This tutorial covers a practical example of lazy loading technique and early loading technique in a Singleton Design Pattern.
How to fix incompatible JVM issue while installing Eclipse While installing Eclipse in windows, got one error like above and unable to proceed with the installation. This video describes how to successfully install Eclipse. How to solve incompa…
Suggested Courses

610 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question