I have already set the classpath to mysql-connector-java-5.0.8-bin.jar and compiled my class successfully. But when I run it I get:
java.lang.ClassNotFoundException: com.mysql.jdbc.Driver
The code is:
import java.sql.*;
public class JdbcExample
{
public static void main(String arg[])
{
try
{
Class.forName("com.mysql.jdbc.Driver");
Connection con=DriverManager.getConnection("jdbc:mysql://loacalhost:3306/sample","root","root");
Statement st=con.createStatement();
ResultSet rs=st.executeQuery("select * from sample");
while(rs.next())
{
System.out.println(rs.getString(1));
}
con.close();
}
catch(Exception e)
{
e.printStackTrace();
}
}
}