• Post Reply Bookmark Topic Watch Topic
  • New Topic

Application Deployment  RSS feed

 
Darren Horsman
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have spent the last few months developing an application in java. It is being released under the Gnu Public License(GPL).

When I was developing it, a lot of the variables were compiled into the application. This includes things like the password and username for the database the application should access data.

The finished version will allow users to chose which database to use (MySQL, PostgreSQL, firebird). This is where the problem lies. Although the variables like the username can be put in a configuration file, to allow the choice of database the choices have to be loaded depending on which one should be used.

As I have all the databases installed for testing, as well as the JDBC drivers, this does not cause any problems BUT for it to be recompiled after changes are made somewhere else, the person compiling it would need all the JDBC drivers mentioned in their classpath or the compiler stops.

As the JDBC drivers are bigger than my application, I do not want to distribute them nor do I wish to hava a different version for each kind of database.

I also considered having the installer recompile the file without the unused databases, but this is not possible as not all users of the application will have a compiler.

My questions boil down to:

  • Although it is not safe, is there a way to make the compiler ignore the JDBC drivers it can't find?
  • Is there another way round the problem that not all users will have the JDBC drivers?

  •  
    Scott Selikoff
    author
    Bartender
    Posts: 4093
    21
    Eclipse IDE Flex Google Web Toolkit
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    There's a few ways to make it ignore the missing JDBC driver, the basic being put a try/catch block around the area that loads the driver. A better solution might be to check for the existing of the class that would be missing if the driver was not installed in that this avoids throwing an exception. Although you couldn't proceed with database work after this, you could display a more meaningful message to the user or allow them to select a different database.

    Unless you're going to write your own JDBC driver, I don't see a solution around the users not having the drivers installed in the general sense. Your application could detect likely JDBC drivers ahead of time and only allow support for those that have valid drivers.
     
    Ernest Friedman-Hill
    author and iconoclast
    Sheriff
    Posts: 24217
    38
    Chrome Eclipse IDE Mac OS X
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    Note that if your application fails to compile when the JDBC drivers aren't present, then you're using JDBC incorrectly! The only driver-specific text should be the Driver class name as a String, and that can easily be read from a configuration file. You can let the user choose the database just by editing the configuration (provide an interface for that if you like).

    Do you mean that it can't "run", or really that it can't compile? Can you show us what won't compile?
     
    Darren Horsman
    Greenhorn
    Posts: 9
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    To Scott Selikoff:

    Enclosing the loading of the drivers in try/catch blocks should be working.

    To Ernest Friedman-Hill:

    The only driver specific lines I thought I had is the String with the driver name in it, I'll look over everything again. Thinking about it after having a rest I realise it should be working as is. I will have another look.

    Thank you.
     
    Stan James
    (instanceof Sidekick)
    Ranch Hand
    Posts: 8791
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    Just for example, I have a bunch of little classes like this. They'll compile whether the drivers are present or not. They'll blow up at run time without the right driver of course.

    (There's an extra space in : DB2: to avoid making a smiley) Here are the other public methods on the wrapper:

    I can instantiate wrappers for any number of connections to different databases from different vendors all based on configuration. Good clean fun.
    [ December 04, 2005: Message edited by: Stan James ]
     
    Darren Horsman
    Greenhorn
    Posts: 9
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    That is all the code I thought I had, there must be something more... specific to make it not compile without the drivers. There should not be though.
     
    • Post Reply Bookmark Topic Watch Topic
    • New Topic
    Boost this thread!