title: Loading jdbc driver to connect to MySQL database
body: <p>I want to connect to my mySQL db with a java program.Im getting a ClassNotFoundException . I copied the mysql-connector-java-5.1.18-bin.jar file to the java lib folder and set classpath in user variables to the java/lib folder. i used the following statements to establish the connection:</p>
  
  <pre><code>Class.forName("com.mysql.jdbc.Driver");
  con=DriverManager.getConnection("jdbc:mysql://localhost:3306/ammy","system","system");
  </code></pre>
  
  <p>Error:</p>
  
  <pre><code>java.lang.ClassNotFoundException: com.mysql.jdbc.Driver
  at java.net.URLClassLoader$1.run(URLClassLoader.java:200)
  at java.security.AccessController.doPrivileged(Native Method)
  at java.net.URLClassLoader.findClass(URLClassLoader.java:188)
  at java.lang.ClassLoader.loadClass(ClassLoader.java:307)
  at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301)
  at java.lang.ClassLoader.loadClass(ClassLoader.java:252)
  at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:320)
  at java.lang.Class.forName0(Native Method)
  at java.lang.Class.forName(Class.java:169)
  at JDBCEx.main(JDBCEx.java:11)
  </code></pre>
  
  <p>This is what i get when i try to extract the jar file:</p>
  
  <pre><code>C:\Program Files\Java\jdk1.6.0_16\lib\mysql-connector-java-5.1.18-bin;.
  Access is denied
  </code></pre>