
JAVA JDBC connectivity problem. I am using MySql database, also I have downloaded and configure JDBC Connector. In the end of this code please see the error that I am getting.
package com.ct;
import java.sql.Connection; import java.sql.DriverManager; import java.sql.ResultSet; import java.sql.SQLException;
public class DbDemoConnection { public static void main(String args[]) throws ClassNotFoundException, SQLException { Connection conn =null; ResultSet rs = null; try{ Class.forName("com.mysql.Jdbc.Driver"); conn = DriverManager.getConnection( "jdbc:mysql://vicky-PC/student"); rs = conn.createStatement().executeQuery("select * from student");
while (rs.next()) { System.out.println(rs.getString("name")); } }catch (ClassNotFoundException cnfEx){ throw cnfEx; }catch (SQLException sqlEx){ throw sqlEx; }finally{ if(rs!=null){ rs.close(); } if(conn!=null){ conn.close(); } } } }
This is the following error I am getting:
Exception in thread "main" java.lang.ClassNotFoundException: com.mysql.Jdbc.Driver at java.net.URLClassLoader$1.run(Unknown Source) at java.security.AccessController.doPrivileged(Native Method) at java.net.URLClassLoader.findClass(Unknown Source) at java.lang.ClassLoader.loadClass(Unknown Source) at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source) at java.lang.ClassLoader.loadClass(Unknown Source) at java.lang.Class.forName0(Native Method) at java.lang.Class.forName(Unknown Source) at com.ct.DbDemoConnection.main(DbDemoConnection.java:13)

Put mysql-connector-java-5.0.8-bin.jar file in your jdk and jre lib.

You have imported wrong driver name. Here is an example:
import java.sql.*;
class RetrieveData
{
public static void main(String[] args) throws Exception
{
Class.forName("com.mysql.jdbc.Driver").newInstance();
Connection conn = DriverManager.getConnection("jdbc:mysql://localhost:3306/test", "root", "root" );
Statement st=conn.createStatement();
ResultSet rs=st.executeQuery("select * from data");
while(rs.next()){
String name=rs.getString("name");
String address=rs.getString("address");
String contact=rs.getString("contactNo");
String email=rs.getString("email");
System.out.println(name+" \t "+address+" \t "+contact+" \t "+email);
}
}
}

Thank you so much :)

add mysql-connector-java-5.0.8-bin.jar in your class path
If you are facing any programming issue, such as compilation errors or not able to find the code you are looking for.
Ask your questions, our development team will try to give answers to your questions.