Hi,
I am writing a desktop application. It would make my life easier if the application can save all it's data in a database software. Do typical desktop applications come packaged with 3rd party database software or do they rely on internal serialized data structure? If 3rd party database applications are used, which ones are most popular? Many thanks in advance.

It all depends on the nature of the app, but yes, many use a database to store information. The database choice depends on your application needs. If you need a central database for many client apps, take a look at Postgre SQL or MySQL. If each clients data is self-contained, a file-based DB like H2 or Mckoi is very easy to integrate, as you don't have to mess with a separate installation and setup of the database.

Thank you for your reply. So what you are saying is that I can simply include the database program with the rest of the software and the database program does not have to be installed on the computer as a seperate program.
Do you know which one of these databases is more popular? I have worked with MySQL and Postgres but I have never even heard of H2 or MKoi. So I will probably need a lot of online support from other people.

So what you are saying is that I can simply include the database program with the rest of the software and the database program does not have to be installed on the computer as a seperate program.

You need to stright-up your facts... Lets put it this way.
Your application will work with database, but that does not mean it will not provide database program. Your program will provide a way to access this database and way to read/write/validate data from it. Database does not have to by instaled on the machine on which you run your program, but it have to have a way to access this database.

Thank you for your reply. So what you are saying is that I can simply include the database program with the rest of the software and the database program does not have to be installed on the computer as a seperate program.
Do you know which one of these databases is more popular? I have worked with MySQL and Postgres but I have never even heard of H2 or MKoi. So I will probably need a lot of online support from other people.

Mckoi and H2 are both Java file-based DBs, so the DB is just a directory of files and the engine is a jar file that you include with your program. Both are very easy to learn to use from the documentation.

We are currently using Mckoi, but have a few speed issues with very large tables (300,000+ records) and development on it seems to have mostly died since last year. We've begun evaluating H2 and are liking it so far.

Apache Derby is another option you could look into. We cannot switch over to that right now because it has no support for a boolean data type and their SQL parser will not evaluate an int (or byte or whatever) as a boolean, so we would have to change too much code internally.

I don't understand the part about adding the jdbc driver to the classpath part. I do not wish to create a new classpath or add the driver to the java sdk installation folder. Doing these will ruin portibility. Is there a way for me embed the driver in my program so the program will run now matter what computer its on? Thank you.

You will have to distribute the database jar file with your app. It can simply reside in a /lib folder. You definitely do not need to add it to the JDK folder.

As far as the classpath, it is not uncommon at all to have a batch program that sets the desired classpath prior to launching the program. If you are distributing your app as an executable jar file, the files in your lib folder can be added to the Class-Path property in your manifest.mf file. If that is done, you won't even need to set the classpath prior to execution.

I am using a simple command line utility. How do I use a /lib folder or manifest.mf? Is there a simple way?

Yes, there are other ways to deploy your app. See the following:
http://java.sun.com/docs/books/tutorial/deployment/index.html

In particular, I would recommend an executable jar file.

A lib folder is nothing more than a folder named "lib" in your application root directory where third-party libraries are placed. It's just a common convention.

I'm realy interested how this work also. Never did it before....
Would you mind Ezzaral to elaborate on the question? How exactly you point your application toward this JAR file?

I'm realy interested how this work also. Never did it before....
Would you mind Ezzaral to elaborate on the question? How exactly you point your application toward this JAR file?

If you are asking about the executable jar file, the jar file is the application. In Windows you can just double-click it to run (not sure how other OS handle that) or you can run it with java -jar MyApp.jar .

The main class of the application is specified in the jar manifest file by a property called Main-Class. This is the class that contains the main() method to execute when the app is run.

The classpath for other dependencies outside of your own jar file, such as third-party jar file libraries your app needs, is specified by the Class-Path entry in the manifest.

The manifest allows you to specify pretty much all of the info Java needs to run your program with the exception of command line options. Those you would still need to set in a batch file or shortcut to execute the program.

You can package up the entire app directory stucture in a single zip file such as the following

/MyApp.jar
/RunMyApp.bat (if you need to set switches on the java command)
/config.xml
/images/(any image resources here if you need them)
/lib/(other jar files your app depends on like JDBC dirvers,etc)

More info here if you need it:
http://java.sun.com/docs/books/tutorial/deployment/jar/index.html

Not exactly what I had in mind. I do know how to create JAR and how to run it. What interest me is how you gone tell your application where to find JAR file which is inside your lib folder?

/lib/(other jar files your app depends on like JDBC dirvers,etc)

For instance I wish to include customize look&feel which is already compresed into JAR file and store in this lib folder.

Ah, ok, sorry I misunderstood you. Class path is all you need to specify to tell your app where to find those files. Class path is merely a list of locations to look for classes that it needs to import. If those are not in the default Java jar files, you need to specify them with either a %CLASSPATH% environment variable, via the -cp switch on the command line, or by listing them in the Class-Path entry in the jar manifest file.

More info on class path can be found here:
http://java.sun.com/j2se/1.3/docs/tooldocs/win32/classpath.html

Allow me to be more specific. At this point I think that my syntax is correct. The error is somewhere else. I am trying to execute the following code:

import java.sql.*;

public class EmbeddedDatabaseDemo {

    public static void main(String[] args) {

    // Register the Mckoi JDBC Driver
    try {
        Class.forName("com.mckoi.JDBCDriver").newInstance();
    }
    catch (Exception e) {
        System.out.println(
        "Unable to register the JDBC Driver.\n" +
        "Make sure the JDBC driver is in the\n" +
        "classpath.\n");
        System.exit(1);
    }

    // This URL specifies we are connecting with a local database
    // within the file system.  './db.conf' is the path of the
    // configuration file of the database to embed.
    String url = "jdbc:mckoi:local://./mckoi1.0.3/db.conf";

    // The username / password to connect under.
    String username = "admin_admin";
    String password = "pass2000";

    // Make a connection with the local database.
    Connection connection;
    try {
        connection = DriverManager.getConnection(url, username, password);
    }
    catch (SQLException e) {
        System.out.println(
        "Unable to make a connection to the database.\n" +
        "The reason: " + e.getMessage());
        System.exit(1);
        return;
    }

    try {
    
        // .... Use 'connection' to talk to database ....


        // Close the connection when finished,
        connection.close();

    }
    catch (SQLException e) {
        System.out.println(
        "An error occured\n" +
        "The SQLException message is: " + e.getMessage());
        return;
    }

    }

}

But it throws the first exception saying that It couldn't register the driver. I have compiled and ran the code with the neccessary jar in the same folder. And also tried the -cp switch with the javac command. The directions for installing the driver is simple. They are on this page if you wish to take a look: http://www.mckoi.com/database/JDBCDriver.html#1
What am I doing wrong?

Your connection code works just fine for me. I believe you still don't have the class path quite right. You said you used -cp with the javac command, but what about when you run it with the java command? Try

java -cp /mckoi1.0.3/mckoidb.jar; EmbeddedDatabaseDemo

You may have to alter that classpath to match your jar location if I inferred it incorrectly.

javac -cp./mckoi1.0.3/mckoidb.jar ./EmbeddedDatabaseDemo.java

Compiles fine. But
java -cp /mckoi1.0.3/mckoidb.jar; EmbeddedDatabaseDemo
is not working. It prints out the java usage file as
if my synatax were incorrect. Can you see what I am
doing wrong?

javac -cp./mckoi1.0.3/mckoidb.jar ./EmbeddedDatabaseDemo.java

Compiles fine. But
java -cp /mckoi1.0.3/mckoidb.jar; EmbeddedDatabaseDemo
is not working. It prints out the java usage file as
if my synatax were incorrect. Can you see what I am
doing wrong?

Try java -cp ./mckoi1.0.3/mckoidb.jar; EmbeddedDatabaseDemo I think you need the "." in front of the path entry if you are referring to a relative folder. I assume you have the jar in a folder /mckoi under whatever directory your class is in?

I did put the '.' before the '/'. I did not show it in my post by mistake.

Hrmm, not sure what the trouble there is then. I recreated that exact path situation(for the jar) and a copy of your class and ran it here with no problems.

java -cp ./mckoi1.0.3/mckoidb.jar; EmbeddedDatabaseDemo is the command I used. How can the same command produce syntax error on computer and work on the other?
My computer must be possesed. I will try a different computer and post back.

java -cp ./mckoi1.0.3/mckoidb.jar; EmbeddedDatabaseDemo is the command I used. How can the same command produce syntax error on computer and work on the other?
My computer must be possesed. I will try a different computer and post back.

You can actually do away with the "./" altogether and just use "mckoi1.0.3/mckoidb.jar", but really I can't see any reason why the command would be balking and printing the usage.

HI
Iam ready to do this project. Please send your requirement to this email id : <email address removed>

Regards
Deepak Xavier

HI
Iam ready to do this project. Please send your requirement to this email id : <email address removed>

Regards
Deepak Xavier

This thread is not seeking someone to complete this work. It is merely discussing some technical questions that the original poster has. Please do not hijack threads offering to solve them for pay. This is not the forum for that.

I shouldn't have to set the classpath if I compile and run and my java class with the neccessary jars in the same folder, am I right? Because I did it and and it is still throwing the same 'can't find JDBC' exececption. How could this be possible? Everything is in the same folder now. Any suggestions?

I am able to run the EmbeddedDabaseDemo.class if I unpack mkjdbc.jar and mckoidb.jar files. Is this what I am supposed do?(doubtful...) Will my program always run if I unpack all the jars and start programming?

I finally got it. Its java -cp .:./mckoi1.0.3/mkjdbc.jar EmbeddedDatabaseDemo. Thanks to everyone who posted on this thread.
The end.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.