Monday, June 2, 2014

How to use JDBC-ODBC in a 64-bit JVM with a 32-bit version of Office

When using the JDBC-ODBC bridge in the JDK to access Microsoft Access files, you would set your JDBC class to sun.jdbc.odbc.JdbcOdbcDriver and your JDBC URL, for example, to:

"jdbc:odbc:Driver={Microsoft Access Driver (*.mdb, *.accdb)};DBQ=C:\CodeStreet\sample.accdb"

So far so good, but in case you are running a 64-bit JVM with a 32-bit Microsoft Office installation, your JVM and Access driver architecture don't match  and you would see error messages such as:
java.sql.SQLException: [Microsoft][ODBC Driver Manager] Data source name not found and no default driver specified


or
"The setup routines for the Microsoft Access Driver .. could not be found."

Fortunately, there are now 64-bit Microsoft Access drivers available, but using them in this context is quite tricky. Once you install the drivers, Microsoft Office stops working !

Opening an Excel file, for example, tries to find the 64-bit version of Office, which you don't have :-(

Instead of opening a file, you will see "Configuration Progress" and "Configuring Microsoft Office Professional Plus 2010..." - what the heck ?

But there's a neat little workaround which goes like this: 

1. Download the Microsoft Access drivers  

2. Check this registry key:
    HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Office\14.0\Common\FilesPaths 

If if currently contains an entry with mso.dll, you are using Office 64-bit, which is ok. If there is NO mso.dll key then your Office version is 32-bit. 

3. Open a command prompt and install the 64-bit driver in passive mode (it won't let you do this any other way):
    AccessDatabaseEngine_X64.exe /passive

4. If  mso.dll was not in your registry in step 2, then remove this key now from
    HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Office\14.0\Common\FilesPaths 


Microsoft Office (32-bit) should start working again and your 64-bit Access drivers are ready to go.



Good Luck!
 

Monday, December 3, 2012

Debugging Java Thread CPU usage

In case you want to quickly find out which of your Java threads is the culprit in a JVM's high CPU usage, this tool is truly helpful.

Simply download topthreads.jar from http://lsd.luminis.nl/top-threads-plugin-for-jconsole/
and run your jconsole like this:

     jconsole -pluginpath topthreads.jar

Similar to 'jtop', just a little better.




Tuesday, October 9, 2012

Eclipse and native library not found

Eclipse as Java IDE is great. But there's (at least) one part of the GUI that's a bit cumbersome. One thing that frequently pops up is the problem of not finding a native library.

For example if you use TIBCO Rendezvous, your project uses a tibrvj.jar file which is dependent on a native libary, for example tibrv.dll on Windows. Of course you can solve this by setting a Run Configurations 'VM argument' to -Djava.library.path=. But if you have many Run configurations, for example because you write JUnit tests around your software, it would be a pain to configure java.library.path for every JUnit Run Configuration.

You would think you can do Project -> Properties -> 'default java library path' - or so.
Or maybe Windows -> Preferences -> 'default VM arguments'. But neither exists :-(
That's the part where I say the GUI design of Eclipse could be improved: it's not quite obvious that you can actually edit properties of a jar file in 'Referenced Libraries'. You add jar files and they look like non-editable references to files. But you can actually change some properties.

Select your jar file and do a right-mouse-click:


In this dialog you can specify the path to a dependent native library which is then added to your java.library.path for every existing and future Run Configuration of this project.

Another interesting jar-file setting is the 'Javadoc Location'. Once you specified the path to a Javadoc's index.htm, the online documentation will be available when you program against that API (IntelliSense and F2 work). For TIBCO Rendezvous however, there's no real Javadoc part of the product.

Please note, though, that when you upgrade to another version of the jar file, these jar-file settings are lost. You have to repeat the steps above. It would be nice from Eclipse to be asked whether to keep Javadoc Location/Native Library settings when upgrading a jar file.


Tuesday, July 12, 2011

Eclipse doesn't start after crash

After a crash on Windows 7, my beloved Eclipse environment wouldn't start again! It just hung there, showing nothing but the Splash screen. eclipse -clean didn't help, monitoring files with Sysinternal's ProcMon or 'handle.exe' didn't help - quite devastating... But finally I found the solution here:
  1. cd to your Eclipse home directory
  2. cd .metadata/.plugins
  3. ren org.eclipse.core.resources BAK (Keep this directory around)
  4. Restart Eclipse, ignore the error message.
  5. Close all open editors tabs !! (in my case, playing with the .xsd file editor caused the issue)
  6. Exit Eclipse.
  7. del org.eclipse.core.resources (Delete the newly created directory.)
  8. ren BAK org.eclipse.core.resources (Restore the original directory.)
  9. Restart Eclipse.

Wednesday, December 15, 2010

How to implement a 'repeating' Swing JButton ?

Sometimes you want to repeat your JButton action after the button was pressed. This is definitely not rocket-science, but I thought it's nice and small enough to share. Here's the usual code with a one-click action: a 'Next' button that selects the next row in a table.

    nextButton.addActionListener( new ActionListener() {
      public void actionPerformed(ActionEvent arg0)
      {
        selectNextRow(...);
      }});
For a repeating button, you can replace this code with the code snippet below. Adjust the times appropriately. I wonder why this isn't standard functionality in a Swing JButton(..., startMsec, repeatMsec) ?

    nextButton.addMouseListener( new MouseAdapter() {
      
      Timer repeatTimer;
      
      public void mousePressed(MouseEvent arg0)
      {
        selectNextRow(...); // initial execution
        
        repeatTimer = new Timer(100, new ActionListener() {
          public void actionPerformed(ActionEvent e)
          {
            selectNextRow(...); // execute every 100 msec
          }});
        repeatTimer.setInitialDelay(1000); // start repeating only after 1 second
        repeatTimer.start();
      }
      
      public void mouseReleased(MouseEvent arg0)
      {
        repeatTimer.stop();
      }});

Tuesday, May 18, 2010

Managing Oracle Tablespace (ORA-01653 error)

This procedure helped me a bit to manage an Oracle DB's tablespace. I was getting ORA-01653: unable to extend table SYSTEM... errors.
Maybe the following procedure is useful for others as well:
  1. In order to manage/see the current usage, here's a good script posted by 'bipul' on http://forums.oracle.com/forums/thread.jspa?messageID=3590569
  2. To check which data files are used:

    select name from v$datafile

  3. To increase that setting:
alter database datafile 'C:\ORACLEXE\ORADATA\XE\SYSTEM.DBF' autoextend on next 100m maxsize 2000m;

Wednesday, February 24, 2010

Quants

An interesting documentation about quants, including Emanuel Derman,
starts in Dutch first, but in English later.