dimanche 3 mai 2015

How to use the ODBC 64 bit to read the excel file in Windows 7 64 bit machine

I need to read the excel file through ODBC 64 bit in my windows 7 64 bit machine.

By default in my system there are two odbcad32

  1. [32-bit] C:\Windows\SysWOW64\odbcad32 (It contains the microsoft excel driver)
  2. [64-bit] C:\Windows\System32\odbcad32 (It doesn't have the microsoft excel driver)

Since, the system doesn't have the Microsoft Excel Driver in the 64 bit ODBC, I downloaded the AccessDatabaseEngine_x64 and installed it.

After the successful installation under

[64-bit] C:\Windows\System32\odbcad32 the Microsoft Excel Driver is present.

Now when I run the java program through eclipse. An error message is displayed like

No suitable driver found for jdbc:odbc:Driver={Microsoft Access Driver (*.mdb, *.accdb)};DBQ=C:/Users/ashokkumarg/Desktop/Excel/TestCaseData.xls

But the same code works very well in the Windows 32 bit machine. I dont know what could be the cause.

Java version

Windows 7 32 bit Machine (where the code works) 1.7.0_51

Windows 7 64 bit Machine (where the code fails) 1.8.0_31

CODE

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;


public class ConnectionTest {

public static void main(String[] args) throws SQLException {

Connection c = null;
Statement stmnt = null;


System.out.println("Test case is started Running");
try{


c = DriverManager.getConnection( "jdbc:odbc:Driver={Microsoft Access Driver (*.mdb, *.accdb)};DBQ=C:/Users/ashokkumarg/Desktop/Excel/TestCaseData.xls");

stmnt = c.createStatement();
String query = "select * from [TestCase$];";
ResultSet rs = stmnt.executeQuery( query );

while( rs.next() )
{
System.out.println( rs.getString( "Page" ));
}
}
catch(Exception e){
e.printStackTrace();
}
}
}

I have few questions over here:

  1. When two odbcad32 is present, How to read the excel file using ODBC 64 bit in Windows 7 64 bit machine.

  2. While running the program whether it is taking the 32 bit odbcad32 driver details. If so how do I need to configure the ODBC 64 bit drivers to use it in the program.

Aucun commentaire:

Enregistrer un commentaire