java - Trying to connect to MS Excel 2007 [wtihout creating DSN] - Error: Data source name not found and no default driver specified -


i trying connect ms excel , read db using below code -

class.forname("sun.jdbc.odbc.jdbcodbcdriver");         connection = drivermanager.getconnection("jdbc:odbc:driver={microsoft excel driver (*.xls, *.xlsx, *.xlsm, *.xlsb)};dbq="+"c:\\excel.xls"+";readonly=false");         statement = connection.createstatement(resultset.type_scroll_insensitive, resultset.concur_updatable);         resultset rs = stmnt.executequery( query );         return rs; 

but getting following error -

java.sql.sqlexception: [microsoft][odbc driver manager] data source name not found , no default driver specified     @ sun.jdbc.odbc.jdbcodbc.createsqlexception(unknown source)     @ sun.jdbc.odbc.jdbcodbc.standarderror(unknown source)     @ sun.jdbc.odbc.jdbcodbc.sqldriverconnect(unknown source)     @ sun.jdbc.odbc.jdbcodbcconnection.initialize(unknown source)     @ sun.jdbc.odbc.jdbcodbcdriver.connect(unknown source)     @ java.sql.drivermanager.getconnection(unknown source)     @ java.sql.drivermanager.getconnection(unknown source)     @ com.ibm.testcaseautomation.driver.excel.execqry(excel.java:18)     @ com.ibm.testcaseautomation.driver.junitdriver.main(junitdriver.java:59)     @ sun.reflect.nativemethodaccessorimpl.invoke0(native method)     @ sun.reflect.nativemethodaccessorimpl.invoke(unknown source)     @ sun.reflect.delegatingmethodaccessorimpl.invoke(unknown source)     @ java.lang.reflect.method.invoke(unknown source)     @ org.junit.runners.model.frameworkmethod$1.runreflectivecall(frameworkmethod.java:47)     @ org.junit.internal.runners.model.reflectivecallable.run(reflectivecallable.java:12)     @ org.junit.runners.model.frameworkmethod.invokeexplosively(frameworkmethod.java:44)     @ org.junit.internal.runners.statements.invokemethod.evaluate(invokemethod.java:17)     @ org.junit.runners.parentrunner.runleaf(parentrunner.java:271)     @ org.junit.runners.blockjunit4classrunner.runchild(blockjunit4classrunner.java:70)     @ org.junit.runners.blockjunit4classrunner.runchild(blockjunit4classrunner.java:50)     @ org.junit.runners.parentrunner$3.run(parentrunner.java:238)     @ org.junit.runners.parentrunner$1.schedule(parentrunner.java:63)     @ org.junit.runners.parentrunner.runchildren(parentrunner.java:236)     @ org.junit.runners.parentrunner.access$000(parentrunner.java:53)     @ org.junit.runners.parentrunner$2.evaluate(parentrunner.java:229)     @ org.junit.runners.parentrunner.run(parentrunner.java:309)     @ org.eclipse.jdt.internal.junit4.runner.junit4testreference.run(junit4testreference.java:50)     @ org.eclipse.jdt.internal.junit.runner.testexecution.run(testexecution.java:38)     @ org.eclipse.jdt.internal.junit.runner.remotetestrunner.runtests(remotetestrunner.java:467)     @ org.eclipse.jdt.internal.junit.runner.remotetestrunner.runtests(remotetestrunner.java:683)     @ org.eclipse.jdt.internal.junit.runner.remotetestrunner.run(remotetestrunner.java:390)     @ org.eclipse.jdt.internal.junit.runner.remotetestrunner.main(remotetestrunner.java:197) 

i using windows 7 64 bit. tried jdk 1.7 (both 32 , 64 bit, changing winodws ->preferences) no luck.

ms office version 2007.

finally, got work.

  1. one need jdk 32 bit. point eclipse jdk 32 bit windows->preferences
  2. even after step 1, system library still points 64 bit. remove , change 32 bit manually under java build path->libraries. above lines, work.

image


Comments

Popular posts from this blog

java.util.scanner - How to read and add only numbers to array from a text file -

rewrite - Trouble with Wordpress multiple custom querystrings -