I’m trying to make my program read/write in a database. I found this sample code to connect which compiles without problems:
“http://webhelp.ucs.ed.ac.uk/services/mysql/example2-java.php”
but Im having issues running it. Whenever I execute I get
Failed to load mysql driver
java.lang.ClassNotFoundException: com.mysql.jdbc.Driver
Do I need to download the driver manually and supply it through classpath or is it already given in java?
EDIT Alright, so I downloaded the driver but how can I run it with classpath to use the driver? I got this as my batch command but it gives me an error:
java -classpath driver/mysql.jar MySQL
and the error is
Error: Could not find or load main class MySQL
While without the classpath it finds the MySQL class :S
EDIT FIGURED IT OUT 😀
java -cp .;./driver/mysql.jar MySQL
You need to download it. I would add it to a
lib/directory (in your project) and add that directory to your classpath.