How to bundle an Access database with a Java application - java

Hi recently I had created a Java application included database with Microsoft Access. I had wrapped it to jar file using eclipse. I pass the jar file to my friend to try to use it. But my friend told me that that is no database connection. How can i include the microsoft access in the jar file. Which mean when my friend double click the jar file it will auto configure the microsoft access database? is that possible?

Actually you don't need a package access with your application, since all versions of windows include a copy of the jet database engine. In other words you can use windows scripting to open up an access database on a windows computer without having installed ms access at all. The component or database engine part is all that you need to open in read those access database files.
Here a windows script to open a access database and write a column out to a text file:
Set dbEng = CreateObject("DAO.DBEngine.36")
strMdbFile = "C:\Docs\MultiSelect.mdb"
Set db = dbEng.OpenDatabase(strMdbFile)
strQuery = "select * from contacts"
Set rs = db.OpenRecordset(strQuery)
rs.MoveFirst
If rs.EOF = True Then
Quit
End If
strTextOut = "C:\t5.txt"
Set fs = Wscript.CreateObject("Scripting.FileSystemObject")
Set ts = fs.OpenTextFile(strTextOut, 2, True)
'2 = write, 1 = read
Do While rs.EOF = False
strOutText = rs("LastName")
ts.Writeline strOutText
rs.MoveNext
Loop
ts.Close
rs.Close
So there is no requirement to package or install the jet database engine width your application since that component is available in windows.
It's probably not too important, but I should point out that there's a distinct difference between ms access the developer's tool to let you write code, build forms, and build reports, and that of the database engine that access developers, vb6, vb.net and in your case Java can use to read an access database file. You don't need ms-access installed here, but only the database engine. That database engine is included with every copy of windows.

First of all: does your friend has a MS Access runtime, maybe he needs it? Does he configured the Microsoft Access ODBC Data Source?
Please take a look at following links: Jackcess - java library for reading and writing to MS Access file (no runtime needed), SQLLite - another file RDMS. Please consider to use the Apache Derby project - you can embed it into your application what gives you some advantages but requires more work. I don't know what app you want to implement so you will have to make a choice by yourself ;).

I don't think so. Your friend'll have to configure the odbc connection from the control panel. Also, I would suggest using a DB like derby or MySql than MS Access as the odbc driver is considered to have many bugs. Also using an embedded DB like derby wouldn't require your friend to configure anything at all.

Related

Custom path for 1 Mongodb Database

I'm developing tool (in Java) that works with files on external HDD. According to my idea program and DB should store on external drive and work on any windows PC.
Could I somehow locate my mongodb database on this external HDD?
UPD.
To connect to DB I do:
mongoClient = new MongoClient(new MongoClientURI("mongodb://localhost:27017"));
database = mongoClient.getDatabase("baseName");
How could I set path to DB files?
Since the paths change from one computer to another it will be hard to detect your database, also the case for multiple external hardrives connected to a computer would make this even worse.
My suggestion is this: Use a file chooser (JFileChooser in java) with the proper error messages in case the user selects the wrong files, that way you can always select your database and use it from any computer.

Sync MySQL Databases via SSH using Java

I have a MySQL database installed in my Amazon AWS instance (not RDS). The same database is installed in a personal computer, offline.
You have to connect to the amazon database via SSH, it is in a Ubuntu instance.
The online database contains information of 1000 users. The offline versions contain information only for that particular user.
Users use a Java desktop application to feed data into the local database. When they click on the Sync button, the 2 databases should be synced. Remember here that the desktop offline database should "upload" the newly inserted things to the online database while it should "download" new data (if any) related only to the particular user .
The system cannot be a manual way where someone manually turn on a 3rd party application, use putty or connect SSH, configure the databases etc and sync. The system should be embedded to the desktop java application.
I looked into things like SymmetricDS and it is too much complicated, not sure about the SSH access too.
Any idea about how to do this in an easy way? I am also creating a REST API thinking I can handle this manually, but if there is already built system/API I am onto it.
This is very simple and doable. Just use MySQL replication.
MySQL replication
Let me know if you want any further details. I can give you working model of my.cnf as well if required.
Br//

Is it possible to save database file in a project folder of Java?

This post is the continue of my previous question in here. So I had a look into how mySQL works with Java, but I noticed that the computer must have a database server to connect to the application. So what will happen when my software is ready and users want to run in a different computers? Can't I save the database file in the directory of the software, so any copy of the program will be connected to its independent database to save and parse data from it?
Just to make it clear, in a part of my software, I needs to keep record of previous interactions. Like a history table.
Would using JSON a better option in this case?
In a real world generally database servers are installed on a machine and softwares are installed on different machine.
We let software know the database configuration like database URL /database Name /username/Passwords etc (through property file or through JNDI configurationS).Then java program can connect to database with the help of JDBC driver.
Note:- one Database Server can Host many databases.
If you want to distribute your software without having dependency on client database. Then I would recommend you to use some inmemory DB.This DB you can embed with your software.(alternatively you can write logic that if client database can't be found then use inMemory DB..something like this).
H2 db is my favorite one and it also supports persistent mode and it support s many DB dialects including MYSQL .

Java application that can run entirely from a DVD

I have to create a java application that can run entirely from a DVD. The application must connect with a database that will be also on the DVD. I was thinking to use an embedded database but i dont know much about them. Do i have to start the database server from my java application and if i do, how should i do it?
Thanks in advance.
Nick Tsilivis
You can use SQLite which is a very light weighted version of SQL. It stores its data in a single file. You even don't have to log in with an username and password. Just add this jar sqlite-jdbc to your projects build path. You cann access it by following:
Class.forName("org.sqlite.JDBC");
Connection connection = DriverManager.getConnection("jdbc:sqlite:your_database.db"); //"your_database.db" is the SQLite database file on your DVD.
/*manipulate your db by using PreparedStatement, ResultSet, ...
You must have installed SQLite on your system SQLite Download
That sounds like a job for SQLite. It runs completely in your own process, so there is no need to start an external database server.

Deploy Java Desktop Application with MS Access DB

This is the first time I am going to deploy the Java Desktop Application with MS Access DB and discovered JAR package is not getting database access other then my development PC though I had the MS access DB in the same directory of the JAR file I have copied after Build the application. And I understand that I cannot connect MS access DB I created with ODBC connection of my PC. Now my question is
How can I deploy Java Desktop Application with MS access BD which will run in any computer where manual ODBC connection to the MS ACCESS DB for every computer will not require ?
I am not trying to connect MS access DB within a net work rather I am trying run this app where MS Access DB is already installed and my supplied DB will be with the JAR file and I want to access the DB I have provided from Java Front End Application.
Please help.
First you should get ODBC driver for Access database. Some computers may don't have it.
After you install that driver you should create ODBC Data Source on computer. I have no idea how to do it in Java, but ODBC Data Source configurations are stored in registry and you can add your Data Source.
Google "registry add odbc data source" or "Can I Create and Delete a DSN Using a Script" (second one is title of good article i found.
Probably you can access registry from java without any problems.
You can also use one of install-maker programs. Some of them have something like "Add Data Source" functionality.

Categories