aspose file tools*
The moose likes JDBC 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 Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Databases » JDBC
Bookmark "ODBC-JDBC connection" Watch "ODBC-JDBC connection" New topic
Author

ODBC-JDBC connection

Hewa Naimanage Sumedha Amalka
Greenhorn

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$]";
stmnt.execute(query);
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 (rsxl.next()) {
String excelemail = rsxl.getString(1);
String excelcategory = rsxl.getString(2);

if (excelemail == null && excelcategory == null) {
break;
}

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

if(rsdb.next()) { // ### 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 !");
this.dispose();
}

else {
p.setString(1,excelemail);
p.setString(2,excelcategory);

p.execute();
p.close();

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


stmnt.close();
dbsta.close();

connexl.close();
conndb.close();

}

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.execute(query);
> 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: http://aspose.com/file-tools
 
subject: ODBC-JDBC connection