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 Multiple preparedStatements 1 Connection Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Databases » JDBC
Bookmark "Multiple preparedStatements 1 Connection" Watch "Multiple preparedStatements 1 Connection" New topic
Author

Multiple preparedStatements 1 Connection

rastas biggs
Ranch Hand

Joined: Sep 24, 2004
Posts: 41
I'm not to sure if I'm doing this correctly, well as a matter of fact I'd say I'm not as the Update although not returning an error is not updating the second statement ps2.

The ps statement executes OK its the second one that won't execute.

What I'm doing is pulling data writing to a file to ftp across the ether, then I'm storing the PK in a vector in the query loop.

Then I get the values from the vector to use as the argument in this case mobile_phone_number in ststement 2 ps2.

I don't think the batch is executing can some one give me a hand with this.


Jeanne Boyarsky
internet detective
Marshal

Joined: May 26, 2003
Posts: 30537
    
150

Rastas,
Where are you closing the resultsets? It is good practice to do this near where you close the prepared statement.

Also, not that the executeBatch returns an array of integers. So on failure, these integers can be zero rather than throw an exception.


[Blog] [JavaRanch FAQ] [How To Ask Questions The Smart Way] [Book Promos]
Blogging on Certs: SCEA Part 1, Part 2 & 3, Core Spring 3, OCAJP, OCPJP beta, TOGAF part 1 and part 2
rastas biggs
Ranch Hand

Joined: Sep 24, 2004
Posts: 41
Jeanne,

the integers in the arry are not zero, I think that I'm stuck in the loop and the executeBatch is not even reached.

How do i exit Enumeration after the last record? other wise I'll have to write the file string token into ArrayList and use a for/loop based on the ArrayList size.

I know this works but I rather use the Enumeration

RB
[ November 04, 2004: Message edited by: rastas biggs ]
Jeanne Boyarsky
internet detective
Marshal

Joined: May 26, 2003
Posts: 30537
    
150

Rastas,
The loop looks ok to me. What does the console show for the printlns in the loop? Does it execute a certain number of times or infinitely?

Just a note: Iterators are prefered over Enumerations. But that doesn't make a difference for the purposes of this discussion.
Bill Fences
Greenhorn

Joined: Oct 23, 2004
Posts: 9
just the MSN value, i did have another println under the executeBatch and in never hits, mind you I am writing the values to a textfile adding them to the ArrayList, closing the Printer and then processsing the array to use the same connection, if that has any impact at all.

I use a for loop and did a allMSN.size() to limit the loop and it worked fine.

Bill c/o Rastas
[ November 05, 2004: Message edited by: Bill Fences ]
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Multiple preparedStatements 1 Connection