java - Connecting Mysql and eclipse -


i trying connect mysql database hosted on phpmyadmin , eclipse. have imported jdbc bin file package, , accessing phpmyadmin through xampp. code:

import java.sql.connection; import java.sql.drivermanager;  public class database {   public static void main(string[] args) {      try {        connection conn = drivermanager.getconnection("jdbc:mysql://localhost/test", "root", "");        system.out.println("connection successful");     } catch (exception e) {        system.err.println(e);     }   } } 

however when compile it, says:

java.sql.sqlexception: no suitable driver found jdbc:mysql://localhost/test'

what mean? watching youtube tutorial exact same things has established connection.

register driver first:

 class.forname("com.mysql.jdbc.driver"); 

your code should be:

 try {        class.forname("com.mysql.jdbc.driver");        connection conn = drivermanager.getconnection ("jdbc:mysql://localhost/test","root","");        system.out.println("connection successful");  } catch (exception e) {        system.err.println(e);  } 

Comments