Stevi Deter

Ranch Hand
+ Follow
since Mar 22, 2008
Stevi likes ...
Hibernate Spring Java
Merit badge: grant badges
For More
Cows and Likes
Cows
Total received
0
In last 30 days
0
Total given
0
Likes
Total received
0
Received in last 30 days
0
Total given
0
Given in last 30 days
0
Forums and Threads
Scavenger Hunt
expand Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt

Recent posts by Stevi Deter

Pick whichever (video or book) that you think works best for you.

And then write a lot of code. Nothing beats writing code and seeing what happens.

And more importantly -- write code that fails, and figure out why it fails, and how to fix it. Ask questions when you can't figure it out - we're here to help nudge you along until you get that moment of understanding.

You can memorize the book or have perfect recall of the video, but until you write some code and find out why it does or doesn't do what you want, you won't be a Real Programmer[tm].
15 years ago
Jessid,

In order to help you, we'll need some more detail.

Where are you putting the file?

What's the code that's trying to open it?

What exception are you seeing (full stack trace helps)?
15 years ago
This question comes up frequently; search the forum for the words 'add' and 'bean' and you'll get several topics.

The best to look at is this one which includes a reply from Bert explaining where to look in the book for fuller answers.

The summary is that "addXxxListener" is a valid JavaBean method name. In the context of the review question, "addSize" is not. Read the link for more exhaustive detail.
There could be many reasons. What error message are you getting when you try to run from the command line?

The most common reason, in my personal experience, is not having the correct classpath configured, but it really depends.
For all the reasons you just stated!

Are the PreparedStatements being closed? You don't get your automatic closure of the ResultSet without actually closing the PreparedStatements.

If the code isn't following best practices, and it sounds like it's not, fixing it is the Right Thing To Do. Otherwise, you'll just continue to have problems with it.
It might be a good time for a bartender to move this topic to the JDBC forum so you can get a wider range of expertise.

It is accurate that closing a Statement will also close the ResultSet.

If you find that properly closing your ResultSet a/o Statement and connections as you finish with them leads you to still continually hit the cursor maximum for your database you can
  • reexamine your code to find places where you can do more of your work with fewer cursors. Try using batch updates, etc.
  • work with your DBA to determine if increasing the cursor maximum is possible



  • I'd highly recommend focusing as much effort as possible on the first, as it will force you to design the JDBC layer in the most efficient way possible.
    [ May 30, 2008: Message edited by: Stevi Deter ]
    Sunny,

    The number of cursors permitted by your database is what you're concerned with here. JDBC will merrily permit you to open cursors until the database balks.

    What you need to do here is refactor the code so it closes result sets and connections as it goes to prevent this from happening.
    Tyler,

    I think you're looking for the Pattern and Matcher classes. Check the Java Tutorial.

    It seems a fine separation of concerns that String doesn't know how to apply regular expressions to itself.
    15 years ago
    Richa,

    In your example, B is fairly tightly coupled to A.

    B's behavior is dependent on A. If A#getA() changes, it affects what happens in B#gety().

    At risk of confusing you further, I'd point out this example is generally acceptable under the Law of Demeter, as B#gety() is using "only one dot" of A.

    But a better design in this specific example would probably be to refactor B as such:



    This decouples B from A.

    If B really need to consume data from A to perform its behavior, then it's fine to pass in the object and use the "only one dot" level of coupling. But in this example you give, the coupling doesn't appear to be achieving anything, Which is often the case in the sort of arbitrary examples we see when first learning!
    [ May 28, 2008: Message edited by: Stevi Deter ]
    If you check the API for ArrayList.clone(), you'll learn it's a shallow copy. A new ArrayList object is returned, but it contains the same elements (not new copies) of the original ArrayList.

    To see how this works, try this little program:



    The output is:

    list and copy are same object? false
    item 0 is same object? true
    item 0 is equals? true
    item 1 is same object? true
    item 1 is equals? true
    item 2 is same object? true
    item 2 is equals? true
    // here we do String s = list.get(0); s = new String("different");
    item 0 is same object? true
    item 0 is equals? true
    // here we did list.set(0, new String("new"));
    item 0 is same object? false
    item 0 is equals? false
    [ May 28, 2008: Message edited by: Stevi Deter ]
    15 years ago
    Raj,

    For the wildcard characters '_' and '%' in a Like statement, I think you need to use the escape syntax, which lets you define the escape character sequence:



    This example should match any string that has a literal % character.
    Hi, Matt,
    Thanks for doing good work!
    This fails for the same reasons that are discussed in this thread.
    15 years ago
    The quick and dirty answer is to escape the single quote with a second single quote:


    However, it's far better to use parameterized queries if you're going to be accepting input from users to avoid SQL Injection attacks (and just good practice in any case):



    This allows you to avoid worrying about escaping special characters while minimizing security risks like this one
    Always glad to know I've been able to help!