File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes JDBC and the fly likes inserting into a database problems Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Databases » JDBC
Bookmark "inserting into a database problems" Watch "inserting into a database problems" New topic
Author

inserting into a database problems

Bron Czimes
Ranch Hand

Joined: May 09, 2004
Posts: 44
well, I have been looking at this for hours (which could be one of my problems) and I can't seem to work out what is wrong.
i have a servlet that is supposed to be entering some data for me (this is a web-based application by the way). the program works fine, shows no errors, but when I go to check the database, nothing has happened! no data is entered into the table that I specified, and because I'm not getting any error messages whatsoever, I have no idea what the problem is.
The code is....



Can somebody please tell me what is wrong?

[Bear edit: removed potentially offensive slur]
[ October 07, 2004: Message edited by: Bear Bibeault ]
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61196
    
  66

What is the executeUpdate returning? You don't even check.


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Bron Czimes
Ranch Hand

Joined: May 09, 2004
Posts: 44
Thats because I dont need to use the result anywhere. I just need some information generated by my program to be inserted into the database at this point.
I was under the impression that executeUpdate() cannot or should not return a result (throws a SQL exception instead).
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61196
    
  66

It returns the number of records that were updated/inserted/deleted.
Bron Czimes
Ranch Hand

Joined: May 09, 2004
Posts: 44
ok, I tried to do a getResultSet() to see if any thing is returned and it turns up blank :S
so I'm assuming this means that nothing is being updated?? is that the correct assumption to make?


so what do I do now?
Adeel Ansari
Ranch Hand

Joined: Aug 15, 2004
Posts: 2874
i dont know if you can get the result set by getResultSet(), though you are executing executeUpdate().

- why are you doing executeUpdate() with select statement?
- while updating the records, what are you expecting in a resultset mate?
Sonny Gill
Ranch Hand

Joined: Feb 02, 2002
Posts: 1211

Try to change your code as follows



Give an initial value to temp, just to get the program working.
Later you can check for invalid values or other conditions etc.

Use executeQuery() instead of executeUpdate, because you want a ResultSet containing the records returned by the ResultSet.

Hopefully this takes you a step closer to what you are trying to do.

Sonny
Bron Czimes
Ranch Hand

Joined: May 09, 2004
Posts: 44
Thanks Sonny, that helped.
Thanks all.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: inserting into a database problems