Saturday, July 28, 2007

Java Look&Feel and Access

I have recently done a little searching on how to do a few things in Java. I also would like to know Java as well as I would know C++ & C#. On the net I have discovered how to change your look and feel to your native operating system's skin and how to connect to an Access Database using your ordinary JDBC ODBC connection driver...

It was pretty interesting and not so hard at all. I'll give the basics but if you would like to know more about the Java LookAndFeels (the Java term for skin) you can have a look at this site: How to Set the Look and Feel.

Basically to let Java inherit your Windows skin, just add the following before your form component creation code:

catch(UnsupportedLookAndFeelException ex) {}
catch(ClassNotFoundException ex) {}
catch(Exception ex) {}

Yeah and just as I have remembered Java, you must specify the exception handling, unlike C# where you don't have to. Each has it's + and - but anyway, it doesn't matter in this case. Now you can see that when you run your application, it will have your Windows skin. If you are in Linux or whatever, I guess it would take your WindowManager's skin (i.e. KDE, Gnome, etc.)

Now for something that I would find useful also is to connect with an MS Access DB via Java. Now I believe you have to have MS Access installed since it should install it's ODBC driver so that Java can use that driver to connect with. All you need is the following connection string and you are set to modify your Access DB.

String database = "jdbc:odbc:Driver={Microsoft Access Driver (*.mdb)};DBQ=YourAccessDb.mdb;DriverID=22;READONLY=true;";
Connection con = DriverManager.getConnection(database ,"","");

Now the reason I would rather use Java than Access is mainly because I'm am very tired of VBA! I have an existing Access Database and Java is such a more flexible, structured and more preferred language + it is free! Here (if you'd like) you can maybe use Hibernate (haven't tried it myself) for easier SQL queries. Also to migrate from Access to something else like HyperSQL or something is also easier via Java.

I hope you found this useful as I have!

God Bless till next time!

No comments: