0

I have started working with jdbc on UBUNTU. I have set classpath for jar file. I successfully executed the similar program for select query ,but in this program it's giving me an error "java.lang.ClassNotFoundException: com.jdbc.mysql.Driver ".this error is related to classpath and i set it perfectly. What's the problem???

import java.sql.*;
import java.io.*;



class newacc
{

public static void main(String args[])
 {
  String nm,pass,city;



 InputStreamReader is=new InputStreamReader(System.in);
 BufferedReader br= new BufferedReader(is);
Connection con;
Statement st;


try
   {
  //taking input in java

    System.out.println("enter name");
    nm=br.readLine();
    System.out.println("enter password");
    pass =br.readLine();
    System.out.println("enter city");
     city=br.readLine();

//jdbc activities

Class.forName("com.jdbc.mysql.Driver");
con=DriverManager.getConnection("jdbc:mysql://localhost:3306/forjava?user=root&password=123");
st=con.createStatement();
st.executeUpdate("insert into users values("+nm+","+pass+","+city+");");

System.out.println("account opened successfully");

con.close();
}

catch(Exception e)
{
System.out.println(e);
}


}

}
Mark Rotteveel
  • 100,966
  • 191
  • 140
  • 197
  • 1
    How about sharing your classpath setting? – mikemil Feb 13 '14 at 21:28
  • Are you running this from IDE or in Terminal... if ur running in terminal you have to set classpath like this java -cp '/home/dirk/mysql.jar:.' newacc while running .(i think, you closed the terminal in which u ran the last select program). If Your running it from ide make sue that that jar file in Classpath) – Naren Feb 14 '14 at 08:35
  • @mikemil first of all thank you for your reply. I solved this problem.... I wrote "com.jdbc.mysql.Driver " instead of "com.mysql.jdbc.driver" [ :) ]..now everything is working perfectly. – user3307248 Feb 16 '14 at 06:15
  • @Naren thank you for your reply. I corrected my mistake. I mentioned it above. now it's working. – user3307248 Feb 16 '14 at 06:16
  • Possible duplicate of [Connect Java to a MySQL database](http://stackoverflow.com/questions/2839321/connect-java-to-a-mysql-database) – Mark Rotteveel May 12 '16 at 12:39

0 Answers0