aspose file tools*
The moose likes JDBC and the fly likes Web Apps Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Databases » JDBC
Bookmark "Web Apps" Watch "Web Apps" New topic
Author

Web Apps

colin shuker
Ranch Hand

Joined: Apr 11, 2005
Posts: 744
Hi, my code is making me crazy...

I have a banking web application, the user fills out a registration form, presses register,
this takes them to RegistrationServlet which creates a 12-digit membershipNumber, which is stored in the servers MySql database.
Also an email is sent to the person registering giving them this membershipNumber.

The problem is the SQL query.. INSERT INTO... does not seem to work.
But I it did work the first time I ran it after I got my webhost to reload the war file.

I'm thinking it might have something to do with session, since it worked first time.

The two things:

1. creating session bean after user logs in (probably not this)
2. When I send email, I use

But I was using getDefaultInstance before, but I took it out for some reason.


My point is, I have no idea of whats going on, theres no output, I was thinking something about logging,
but I don't know how I can get this to work with my webhosting, I basically just upload a war file, then get it deployed/reloaded.

Can anyone help, thanks
Paul Sturrock
Bartender

Joined: Apr 14, 2004
Posts: 10336


The problem is the SQL query.. INSERT INTO... does not seem to work.

Not completely sure I follow what you think is wrong here. You say the insert fails, is that the case? Do you have a stack trace for this failure?

Then you ask about the JavaMail session - is this failing too?


But I was using getDefaultInstance before, but I took it out for some reason.

What reason?


JavaRanch FAQ HowToAskQuestionsOnJavaRanch
colin shuker
Ranch Hand

Joined: Apr 11, 2005
Posts: 744
Thanks,

well for the INSERT INTO...

It works fine when I run the web app locally in netbeans 6.9, but problematic when I upload war file to server.
The thing is, I donno how to see the stack trace, its not running on my pc, so I was thinking about logging, but I'm confused how to set it up.

For the getInstance(), when I ran locally with getDefaultInstance() it was throwing an exception, something to do with the session.
But getInstance() seems to work fine on the server, it sends an email out every time.

Any thoughts? Thanks
colin shuker
Ranch Hand

Joined: Apr 11, 2005
Posts: 744
I think I may have fixed it, will find out once my war file gets reloaded.

In my database utility class I had a static Connection member.
I was using the same thing for each query without resetting it or anything.
This probably explains why it only worked the first time it was called.

So now, for each query I just create a new connection, and run the query.

Question: I guess I should also close this connection object after I've processed the query?

Thanks
Paul Sturrock
Bartender

Joined: Apr 14, 2004
Posts: 10336

Yes. Always. And in a finally block.
colin shuker
Ranch Hand

Joined: Apr 11, 2005
Posts: 744
Ok, but why always in a finally block?
Cause I have this code..



My point is that conn.close() may also throw an SQLException, so if you put it in a finally block,
you would need another try catch block. The current try catch catches the SQLException anyway,
so I don't see whats wrong with putting it where I have it.

Any thoughts?
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61612
    
  67

Stop. Think.

What happens to the connection if stmt.executeUpdate() throws an exception? Does it get closed?

(P.S. The word statement is spelled "statement" not "stmt" -- vowels don't cost anything)


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
colin shuker
Ranch Hand

Joined: Apr 11, 2005
Posts: 744
Yes you're right, I wasn't thinking.

I just thought nested try catch blocks that catch the same exception seemed a bit funny.
David Newton
Author
Rancher

Joined: Sep 29, 2008
Posts: 12617

Bear Bibeault wrote:(P.S. The word statement is spelled "statement" not "stmt" -- vowels don't cost anything)

They do on Wheel of Fortune.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Web Apps