views:

57

answers:

4

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?

A: 

This previous discussion any use? http://stackoverflow.com/questions/516399/create-exe-for-java-program

Brian
Use those software can create exe file but how about the database part?
A: 

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.

ssr532
Hi thank you for ypur suggestion because I never use derby before will try look into it.
@ssr532: the ODBC driver for *what* is "considered to have many bugs"?
David-W-Fenton
You don't need to configure a DSN to use ODBC. You just need the right connect string.
David-W-Fenton
+1  A: 

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 ;).

Ajan
The application is just a simple budget planner. I was thinking how those commercial software work, so the software can install in other user desktop. Thank You your suggestion
For simply budget planner app I would preffer something like SQLLite (I think it's much better than MS Acces). But if you will ever want to extend functionality of yours app then maybe Derby will be the correct choice. Take a look at http://db.apache.org/derby/javadoc/publishedapi/jdbc4/org/apache/derby/drda/NetworkServerControl.html - you just start a network server and then connect to it through JDBC using connection string: "jdbc:derby://<your_host>:<database_port>/<database_name>".
Ajan
+2  A: 

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.

Albert D. Kallal
Hi in this case this windows script should store inside jar file?
I'm not really sure I understand your question? The above is just a plain Jane windows script (like a windows batch file but is windows scripting). This is just an example of how built in windows scripting can open and read access databases (without access or ANY other software having been installed). I assume your development language supports com objects and thus just modify the above code into whatever language you like. Give the code a try by cut + paste above into notepad. Rename file extension to .vbs. The icon will change from notepad to vbs. Double click on this to run the script.
Albert D. Kallal
How to change the code to run accdb?