It's not a secret anymore!*
The moose likes JDBC and the fly likes ODBC-JDBC connection and Looping Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Java 8 in Action this week in the Java 8 forum!
JavaRanch » Java Forums » Databases » JDBC
Bookmark "ODBC-JDBC connection and Looping" Watch "ODBC-JDBC connection and Looping" New topic
Author

ODBC-JDBC connection and Looping

Hewa Naimanage Sumedha Amalka
Greenhorn

Joined: Oct 31, 2006
Posts: 19
Hai Guys, Thanks for your kind attntion about my software development project!


I have a poroblem in ODBC _ JDBC connection infact the code is working properly, but there is bug in my loob condition and Resultset.next(); mehtod;


I'll give more explanation adout the project;


we need to update records from an excel sheet ( should not be use any convertable softwares !) to MYSQL database. so, I created odbc connection for the excel sheet and jdbc connection to sql database.
The excel sheet columns are
1. email address and 2.category there are thress conditions avalable for this process !

1. if a same record avalable both sql and excle sheet with out change any changes of email or category, it should not be insert or update !

2. if a same record avalable both aql and excel sheet but the email address is equal and deferant category it should update the current cetegory inthe sql database !

3. esle the new record should be inserted.


I made the java code as this but it not working properly and it trys to duplecate the same record


If you have a differenat idea about this pls send to me


Thanks


**** remeber unspecified have been validated in mamber field *******************





[edited to add code tags]

guys if you have any idea adout this code's bug pls reply me !
Thanks agein !
[ November 17, 2006: Message edited by: Jeanne Boyarsky ]

SCJP 1.4 71%, SCWCD 1.5 84%, SCBCD 90%, SCMAD 98%
Jeanne Boyarsky
internet detective
Marshal

Joined: May 26, 2003
Posts: 29287
    
140

Sumedha,
I see a couple of things that could cause a problem:
1) while((rsdb.next())||(rsxl.next())) - Why are you looping through both resultsets here? The excel document is already being looped through in the outer loop.
2) if(excelemail.equals(dbemail) && (!excelcategory.equals(dbcategory))) - If the e-mails weren't equal, the code wouldn't get to this point because it wouldn't have made it to the else and would have just done "continue next"
3) p.execute() - Gets called without setting the parameters/binding variables for the prepared statement.

Note that using labels for continue (next is usually considered poor practice. It makes the code more difficult to understand and maintain.

Try writing a method (it doesn't need to compile) with just the control logic. That way you have the logic done before complicating it with JDBC.


[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
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: ODBC-JDBC connection and Looping
 
Similar Threads
Control the loop of resultset.next( );
ODBC - JDBC connection and Updating MY SQL
What is the best way to do simple update to a very Huge Table
how to write into excel sheet
ODBC-JDBC connection