Win a copy of Head First Go this week in the Go forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Bear Bibeault
  • Paul Clapham
  • Jeanne Boyarsky
Sheriffs:
  • Devaka Cooray
  • Junilu Lacar
  • Tim Cooke
Saloon Keepers:
  • Tim Moores
  • Ron McLeod
  • Tim Holloway
  • Claude Moore
  • Stephan van Hulst
Bartenders:
  • Winston Gutkowski
  • Carey Brown
  • Frits Walraven

Connecting to a Microsoft Access Database in Java  RSS feed

 
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hopefully, I post this thread in the right area. I am learning how to use a database in Java. I am trying to connect to an access database. I have researched the internet and found out that I need to use Ucanaccess. I have followed several tutorials on using Ucanaccess and have been successful. However when I try to distribute my application and move to another computer. I get an error. From the tutorials, I found it said that you need to use the full path to the database. I was wondering if there is a way to access the database without having to use the full path or is another Java-based library that I can use to access the database. I just want to have the flex ability to distribute my application.
 
Marshal
Posts: 24199
54
Eclipse IDE Firefox Browser MySQL Database
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I don't have information about Ucanaccess, but am I right in assuming that you can write some code which figures out what the full path to the database is before you make the connection? I think that's quite likely. And if that's the case then you could modify your application to do that figuring out. Without knowing how you distribute the application it's impossible to advise you on how to do that, but it might involve popping up a file chooser so that the user can tell you where it is. Or it might be in the same folder as the application... or many other possibilities.
 
Master Rancher
Posts: 1163
18
Firefox Browser Hibernate IntelliJ IDE Java MySQL Database Spring Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It's actually as simple as what Paul said, if you keep you're accesdatabase i, ypur projectfolder (in the resource package for example) you can use a relative path and then it dosn't mather where the program is moved to;
An alternative, but kinda the same, A friend of mine's, when writting his thesis, client was also using an acces db, he used the data of the accesfile to create a H2 embedded database, but that writes also everything to a file, so weather you keep your accesfile in your project or you keep de H2file in your project dosn't make that mutch difference, although you can direct H2 as anny real db, so you could use JpaRepositories and stuff, I doubt that's possible with acces, but I also never usd UcanAcces so I could be mistaking
 
Saloon Keeper
Posts: 5289
143
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I advise against using Access. It has problems with concurrency, it only runs on Windows, the JDBC driver choice is limited, etc.

If you don't want to install a proper network-capable DB like PostgreSQL or MySQL, have yon considered using a Java DB like HsqlDB or Derby?
 
Saloon Keeper
Posts: 20514
115
Android Eclipse IDE Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The Microsoft Access and Microsoft FoxPro databases were designed for single-user operation and should not be used for any sort of multi-user application, including web applications, because having multiple users hit an Access database at one time may corrupt the database. For those sorts of applications, a multi-user database server is recommended and there are many to choose from, ranging from Microsoft's own SQL Server to IBM's DB2 to Oracle, to the open-source MySQL/MariaDB and PostgreSQL, Apache Derby, SQLite, and on and on and on.

All of the major SQL databases can be accessed via a universal interface: The Java Database Connection interface (JDBC).  It's a lot like ODBC, except that ODBC really only works with Windows, whereas JDBC drivers can be found for every major OS, making the Java database app "write once/run anywhere".

The ucanaccess driver is a JDBC driver for MS Access, and you can definitely talk to your MS-Access database using that, and it's a lot more suited than the JDBC-ODBC bridge driver that people used to use for that purpose.

Just remember what I said initially - no matter what driver you use, MS-Access is not designed for multi-user applications, so limit its use to learning purposes.
 
Leslie Jenkins
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks, everyone for the advice. The application will be used just for a single user. Currently, we do not have the option to set up a SQL server at this time. I will keep on researching the usage for Ucanaccess for the time being.
 
Daniel Demesmaecker
Master Rancher
Posts: 1163
18
Firefox Browser Hibernate IntelliJ IDE Java MySQL Database Spring Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
as mentioned for a embedded database, you don't need a server, everything is written to a file when to program shut's down and loaded when the program starts
 
Mo-om! You're embarassing me! Can you just read a tiny ad like a normal person?
Become a Java guru with IntelliJ IDEA
https://www.jetbrains.com/idea/
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!