runtime error: java.lang.ClassNotFoundException: com.mysql.jdbc.Driver -


i new mysql , jdbc , getting error in title. have been searching day , cannot find solution works me.

what have tried: uninstall/reinstall mysql, copy paste mysql-connector-java-5.1.25-bin.jar , ojdbc7.jar same location .class file trying run, rebuilt program in different directory, , couple other things.

i using notepad++ coding , windows command prompt compile , run. compiles fine try run with

c:\projects\bin>java -cp . clientbase

the output is:

java.lang.classnnotfoundexception: com.mysql.jdbc.driver

at java.net.urlclassloader$1.run(urlclassloader.java:336)
@ java.net.urlclassloader$1.run(urlclassloader.java:355)
@ java.security.accesscontroller.doprivileged(native method)
@ java.net.urlclassloader.findclass(urlclassloader.java:354)
@ java.lang.classloader.loadclass(classloader.java:432)
@ sun.misc.launcher$appclassloader.loadclass(launcher.java:308)
@ java.lang.classloader.loadclass(classloader.java:356)
@ java.lang.class.forname0(native method)
@ java.lang.class.forname(class.java:188)
@ clientbase.main(clientbase.java:21)
goodbye.

// import packages import java.sql.*;  // create class clientbase public class clientbase{             // jdbc driver name , database url             static final string jdbc_driver = "com.mysql.jdbc.driver";                             static final string db_url = "jdbc:mysql://localhost/clientbase";               // database credentials     static final string user = "root";     static final string pass = "";  // begin method main public static void main(string[] args) {     connection conn = null;     statement stmt = null;      try{         // register jdbc driver         class.forname("com.mysql.jdbc.driver");          // open connection         system.out.println("connecting database...");         conn = drivermanager.getconnection(db_url, user, pass);          // execute query         system.out.println("creating statement...");         stmt = conn.createstatement();         string sql;         sql = "select id, name, address, address 2, city, phone, state, zip, fax clientbase";         resultset rs = stmt.executequery(sql);          // extract data result set         while(rs.next()){             // retrieve column name             int id = rs.getint("id");             string name = rs.getstring("name");             string address = rs.getstring("address");             string address2 = rs.getstring("address2");             string city = rs.getstring("city");             string phone = rs.getstring("phone");             string state = rs.getstring("state");             string zip = rs.getstring("zip");             string fax = rs.getstring("fax");              // display values             system.out.print("id: " + id);             system.out.print(" name: " + name);             system.out.println("address:" + address);             system.out.println(address2);             system.out.print("city:" + city);             system.out.print(" state: " + state);             system.out.println(" zip: " + zip);             system.out.print("phone: " + phone);             system.out.println(" fax: " + fax);         } // end while          // clean         rs.close();         stmt.close();         conn.close();     }catch(sqlexception se){         // handle errors jdbc         se.printstacktrace();     }catch(exception e){         // handle errors class.forname         e.printstacktrace();     }finally{         // block used close resources         try{             if(stmt!=null)                 stmt.close();         }catch(sqlexception se){             se.printstacktrace();         } // end     } // end try system.out.println("goodbye."); } // end method main } // end class clientbase 

i should going off online tutorial code. not how have decided make little different theirs, same. don't think code problem though error is.

any appreciated! i'm going crazy!

you need add connector library runtime classpath:

java -cp .;mysql-connector-java-5.1.25-bin.jar clientbase 

my example uses windows classpath separator ";", on other systems may different (":" on linux/mac). assumes, mysql-connector-java-5.1.25-bin.jar located on same folder. if it's not case, put path library instead of plain name.

clientbase stands java class file name here

c:\>javac test.java c:\>java -cp .;f:\ck\javatest\jdbctutorial\mysql-connector-java-5.1.18-bin test 

Comments

Popular posts from this blog

css - Which browser returns the correct result for getBoundingClientRect of an SVG element? -

gcc - Calling fftR4() in c from assembly -

Function that returns a formatted array in VBA -