aspose file tools*
The moose likes JDBC and the fly likes First Post - Multiple SQL Queries with JDBC Error? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Databases » JDBC
Bookmark "First Post - Multiple SQL Queries with JDBC Error?" Watch "First Post - Multiple SQL Queries with JDBC Error?" New topic
Author

First Post - Multiple SQL Queries with JDBC Error?

Scott Brant
Greenhorn

Joined: Dec 29, 2010
Posts: 2
Hi All,

First post, so please go easy

I am producing a small website for educational purposes, and very new to JSP and the JDBC. I have been stuck all day, on a small piece of code (which have fundamental issues), and hopefully someone can help .

As its the holiday season, i have emailed my tutor for some help but they will not return until early january

Basically, i am trying to run two SQL Queries within the same code, one which inserts data to a table and the other to update another table.

I have attached the area of the code below and the error description.





Hopefully someone can point me in the right direction. I have also tried using a batch execute, but that didnt work either.

Thanks for any assistance,
Scott
Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18898
    
    8

Well, first of all you should be using PreparedStatement to do your insertions and updates. Especially when the data is coming from the user of a web application, you're just asking for an SQL injection attack.

But back to the basic problem. If you want to execute two updates, just execute one and then execute the other. There isn't anything in JDBC which lets you combine two random updates and execute them in one statement.

Oh, and don't use "LIKE" in your where-clause if you really mean "equal". At best you're just making the database do extra work and at worst you'll accidentally update records which shouldn't be updated. There's nothing like updating every record in a table to have the same data to spoil your day. Especially if you didn't have a backup.
Jan Cumps
Bartender

Joined: Dec 20, 2006
Posts: 2510
    
  10

Welcome to the Ranch, Scott.


OCUP UML fundamental and ITIL foundation
youtube channel
Ravi Kiran Va
Ranch Hand

Joined: Apr 18, 2009
Posts: 2234

try this , as what Paul suggested .


Save India From Corruption - Anna Hazare.
Scott Brant
Greenhorn

Joined: Dec 29, 2010
Posts: 2
Thanks All,

In the end, the code didnt work too well. So i opted to run each query over a single page, this wasnt ideal, but as its purely educational it will do.

I will also look into the PreparedStatements, as again the site will not go live, but it would be useful for my own understanding.

Thanks again for your help and time

Scott.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: First Post - Multiple SQL Queries with JDBC Error?