Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Web Apps

 
colin shuker
Ranch Hand
Posts: 750
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 10336
Eclipse IDE Hibernate Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

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?
 
colin shuker
Ranch Hand
Posts: 750
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 750
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 10336
Eclipse IDE Hibernate Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes. Always. And in a finally block.
 
colin shuker
Ranch Hand
Posts: 750
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 65223
95
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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)
 
colin shuker
Ranch Hand
Posts: 750
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Bear Bibeault wrote:(P.S. The word statement is spelled "statement" not "stmt" -- vowels don't cost anything)

They do on Wheel of Fortune.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic