3 Replies - 173 Views - Last Post: 12 December 2012 - 06:20 AM Rate Topic: -----

#1 rishabhsharma  Icon User is offline

  • D.I.C Regular
  • member icon

Reputation: 10
  • View blog
  • Posts: 342
  • Joined: 26-March 09

ClassNotFoundException("com.mysql.jdbcdriver")

Posted 12 December 2012 - 05:25 AM

I have installed MySql and edited my CLASSPATH(variable) to the path specifying the connector.
Now when I am running this code using java TestConnection it gives me ClassNotFoundException.
I am not getting where I am doing wrong. How can I get it correct?

import java.sql.*;

public class TestConnection
	{
   public static void main(String[] args)throws ClassNotFoundException
			{
	Class.forName("com.mysql.jdbc.Driver") ;			
    Connection conn = null;
    String url = "jdbc:mysql://localhost:3306/student";
    String userName = "root"; 
    String password = "twinrdmighty";
    try 
		{
          conn = DriverManager.getConnection(url,userName,password);
		  Statement stat = conn.createStatement() ;
		  stat.execute("create table student(fname varchar(100), lname varchar(100))") ;
		 }
	catch(Exception e)
		{}
          }
} 


This post has been edited by rishabhsharma: 12 December 2012 - 05:41 AM


Is This A Good Question/Topic? 0
  • +

Replies To: ClassNotFoundException("com.mysql.jdbcdriver")

#2 g00se  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 2657
  • View blog
  • Posts: 11,207
  • Joined: 20-September 08

Re: ClassNotFoundException("com.mysql.jdbcdriver")

Posted 12 December 2012 - 05:28 AM

Quote

I have installed MySql and edited my CLASSPATH(variable) to the path specifying the connector.
How? Evidently you haven't done it correctly. How are you running the code? At the command line? A new command window is necessary after the change of any environment variable
Was This Post Helpful? 0
  • +
  • -

#3 rishabhsharma  Icon User is offline

  • D.I.C Regular
  • member icon

Reputation: 10
  • View blog
  • Posts: 342
  • Joined: 26-March 09

Re: ClassNotFoundException("com.mysql.jdbcdriver")

Posted 12 December 2012 - 05:40 AM

Yes I am running the code from command line. And indeed I have used new command window after altering classpath, but for no effect.
I have placed the connector at C:\Program Files\Java\jre7\lib\mysql-connector-java-5.1.11-bin and edited the Classpath with the same path. What am I doing wrong......?

This post has been edited by rishabhsharma: 12 December 2012 - 05:43 AM

Was This Post Helpful? 0
  • +
  • -

#4 rishabhsharma  Icon User is offline

  • D.I.C Regular
  • member icon

Reputation: 10
  • View blog
  • Posts: 342
  • Joined: 26-March 09

Re: ClassNotFoundException("com.mysql.jdbcdriver")

Posted 12 December 2012 - 06:20 AM

Thank you. I have solved the problem. :)
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1