0

I am a begginer in Java, and I managed to create an app that stores (and also displays into a JTable) data into a database located on my computer. I made an executable .jar out of it and it works like a charm (on my PC). My problem comes when I am running that app on another PC.

try{
        Class.forName("oracle.jdbc.driver.OracleDriver");
    }catch(ClassNotFoundException e){
        JOptionPane.showMessageDialog(null, "Can't find driver");
        System.exit(-1);
    }

I always get that message dialog "Can't find driver". I am asking for an answer regarding how to add (somehow) the driver that I need into my executable .jar file in order to run properly on other PCs.

Octavian Mărculescu
  • 4,312
  • 1
  • 16
  • 29

1 Answers1

0

Class.forName() will try to load the class based on its name from the classpath, dynamically(*), so you need to make sure you have the proper class (OracleDriver) on your classpath. Keep in mind it will usually be contained in a .jar, so you need to put that on the classpath.

(*) In this case the driver registers itself when the class is loaded

The easiest way to ensure you have that jar is to distribute it with your project (see licencing for the particular driver whether that is an option in your case)

Attila
  • 28,265
  • 3
  • 46
  • 55
  • I put the jar file (ojdbc6.jar) containing that class on my classpath (Add External JARs) and it still doesn't work. I am starting to think that I am missing something in the Export process. – Octavian Mărculescu Jun 06 '12 at 15:02
  • You could look into the fatjar plugin (hanven't used it myself), or follow the suggestions in [this SO post](http://stackoverflow.com/questions/528007/eclipse-java-export-jar-include-referenced-libraries-without-fatjar) – Attila Jun 06 '12 at 15:07
  • Problem solved! I used Runnable JAR file from the Export menu. Thanks for answering my question Attila ! – Octavian Mărculescu Jun 06 '12 at 15:13