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.
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)