You are on page 1of 3

signup

StackOverflowisaquestionandanswersiteforprofessionalandenthusiastprogrammers.It's100%free,no
registrationrequired.

login

tour

eclipseManipulatinganAccessdatabasefromJavawithoutODBCStackOverflow

11/06/2015

help

stackoverflowcareers

Takethe2minutetour

ManipulatinganAccessdatabasefromJavawithoutODBC
IwanttomanipulateaMicrosoftAccessdatabase(.accdbor.mdbfile)frommyJavaproject.Idon'twanttousetheJDBCODBCBridge
andtheAccessODBCdriverfromMicrosoftbecause:
theJDBCODBCBridgehasbeenremovedfromJavaSE8andisnotsupported(ref:here),
theJDBCODBCBridgedoesnotworkproperlywiththeAccessODBCdriverwhentextincludesUnicodecharacterswithcode
pointsaboveU+00FF(ref:here),sosuchasetupwouldnotbeabletohandlecharacterssuchasGreek,Russian,Chinese,Arabic,
etc.,
theAccessODBCdriverfromMicrosoftonlyworksinWindows,and
thereareseparate32bitand64bitversionsoftheAccessDatabaseEngine(andODBCdriver)whichcanbeanuisancefor
deployment.
IhaveseenotheranswersmentioningaJDBCdriverforAccessdatabasesnamedUCanAccess .HowcanIsetupmyJavaprojectto
usethisapproach?
(AnswerssuggestingbetterwaysofworkingwithAccessdatabasesfromJavawouldalsobemostwelcome.)
java eclipse msaccess netbeans7 ucanaccess

editedMar12'14at15:07

askedFeb22'14at13:55
GordThompson
40k

25

62

GordIwouldliketogetintouchwithyou.Emailaddress,isitpossible?Cheers bonCodigoMar18'14at
15:28

1Answer

UCanAccess isapureJavaJDBCdriverthatallowsustoreadfromandwritetoAccess
databaseswithoutusingODBC.Itusestwootherpackages,Jackcess andHSQLDB,toperform
thesetasks.Thefollowingisabriefoverviewofhowtogetitsetup.

AddtheJARstoyourproject
Asmentionedabove,UCanAccessrequiresJackcessandHSQLDB.Jackcessinturnhasits
owndependencies .SotouseUCanAccessyouwillneedtoincludethefollowingcomponents:
UCanAccess (ucanaccess2.x.x.jar)
HSQLDB(hsqldb.jar,version2.2.5ornewer)
Jackcess (jackcess2.x.x.jar)
commonslang(commonslang2.4.jar,ornewer)
commonslogging(commonslogging1.0.4.jar,ornewer)
Fortunately,UCanAccessincludesalloftherequiredJARfilesinitsdistributionfile.Whenyou
unzipityouwillseesomethinglike
ucanaccess2.0.4.jar
lib/commonslang2.6.jar
lib/commonslogging1.1.3.jar
lib/hsqldb.jar
lib/jackcess2.0.3.jar

Allyouneedtodoisaddallfive(5)JARstoyourproject.
Eclipse:RightclicktheprojectinPackageExplorerandchoose BuildPath>ConfigureBuild
Path... .Clickthe"AddExternalJARs..."buttontoaddeachofthefive(5)JARs.Whenyouare
finishedyourJavaBuildPathshouldlooksomethinglikethis

http://stackoverflow.com/questions/21955256/manipulatinganaccessdatabasefromjavawithoutodbc

1/3

11/06/2015

eclipseManipulatinganAccessdatabasefromJavawithoutODBCStackOverflow

NetBeans:Expandthetreeviewforyourproject,rightclickthe"Libraries"folderandchoose
"AddJAR/Folder...",thenbrowsetotheJARfile.

Afteraddingallfive(5)JARfilesthe"Libraries"foldershouldlooksomethinglikethis:

You'reset!
Now"UCanAccess"datain.accdband.mdbfilesusingcodelikethis
//assumes...
//importjava.sql.*;
Connectionconn=DriverManager.getConnection(
"jdbc:ucanaccess://C:/__tmp/test/zzz.accdb");
Statements=conn.createStatement();
ResultSetrs=s.executeQuery("SELECT[LastName]FROM[Clients]");
while(rs.next()){
System.out.println(rs.getString(1));
}

http://stackoverflow.com/questions/21955256/manipulatinganaccessdatabasefromjavawithoutodbc

2/3

11/06/2015

eclipseManipulatinganAccessdatabasefromJavawithoutODBCStackOverflow

Disclosure
IhavenoinvolvementinoraffiliationwiththeUCanAccessproject.Ijustuseit.
editedApr28'14at12:38

answeredFeb22'14at13:55
GordThompson
40k

25

62

2 Doyouhaveanyaffiliationwiththislibrary?Mightbeworthdisclosingitifyoudo.JoeFeb22'14at
15:10
@JoeThanksforthetip.Ihaveupdatedmyanswer. GordThompson Feb22'14at15:25
CanyouusethistoconnecttoanExcelWorkbook(.xlsx)inJava8?steinbiturMay4'14at13:54
1 @ssThedriverclassis net.ucanaccess.jdbc.UcanaccessDriver GordThompson Sep26'14
at14:06
1 @GordThompsonThatisagreatanswer.Myentireclasswasstuckwiththisissuebelievingittobeafile
systemprivilegeerror.HelpedmeloadsandittookasurprisingamountofdiggingtorealizeOracledone
awaywiththeJDBCODBCbridgefromJava8.wilbomc Jan22at1:23

protectedbyCommunity Dec13'14at19:21
Thankyouforyourinterestinthisquestion.Becauseithasattractedlowqualityanswers,postingananswernowrequires10reputationonthissite.
Wouldyouliketoansweroneoftheseunansweredquestions instead?

http://stackoverflow.com/questions/21955256/manipulatinganaccessdatabasefromjavawithoutodbc

3/3

You might also like