my dog learned polymorphism
The moose likes JDBC and Relational Databases and the fly likes ODBC-JDBC connection Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of REST with Spring (video course) this week in the Spring forum!
JavaRanch » Java Forums » Databases » JDBC and Relational Databases
Bookmark "ODBC-JDBC connection" Watch "ODBC-JDBC connection" New topic

ODBC-JDBC connection

Hewa Naimanage Sumedha Amalka

Joined: Oct 31, 2006
Posts: 19
Hai, guys I was trying to connect a excel sheet data to mysql database. but some of my codes are not working properly

try {
Statement stmnt = connexl.createStatement();
String query = "SELECT * FROM [IJTS$]";
ResultSet rsxl = stmnt.getResultSet();

Statement dbsta = conndb.createStatement();
dbsta.execute("SELECT email_address, category FROM emailrec");
ResultSet rsdb = dbsta.getResultSet();
PreparedStatement p = conndb.prepareStatement("INSERT INTO emailrec(email_address,category) VALUES(?,?);");

while ( {
String excelemail = rsxl.getString(1);
String excelcategory = rsxl.getString(2);

if (excelemail == null && excelcategory == null) {

else {
System.out.println(excelemail + " " + excelcategory);

if( { // ### the error must be here !!!

System.out.println("Comes Here !");

String dbemail = rsdb.getString("email_address");
String dbcategory = rsdb.getString("category");

if(excelemail.equals(dbemail)&& (!excelcategory.equals(dbcategory))) {

// Prepare a statement to update a record
String sql = "UPDATE emailrec SET category ='"+excelcategory+"' WHERE email_address = '"+excelemail+"';";

// Execute the insert statement
int updateCount = stmnt.executeUpdate(sql);
// updateCount contains the number of updated rows

JOptionPane.showMessageDialog(null," Some of your data have been updated !");

else {


JOptionPane.showMessageDialog(null,"Some of your data have been inserted !");




catch( Exception e ) {
System.out.println( e );
it does not show an exception but dont connet with sql database it seems like never ending loop running on this code
just one record is displaying !
pls help to me !

SCJP 1.4 71%, SCWCD 1.5 84%, SCBCD 90%, SCMAD 98%
Wei Dai
Ranch Hand

Joined: Jun 22, 2005
Posts: 86
> stmnt.executeUpdate(sql)
>int updateCount = stmnt.executeUpdate(sql);
Create another statement object for the 2nd and 3rd sql opeartion, otherwise your rsdb is in unkown status.
I agree. Here's the link:
subject: ODBC-JDBC connection
It's not a secret anymore!