So I want to retrieve one row of the table but first I want to make it works and then I will do the rest, so below is the code:
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.io.*;
import java.util.*;
import java.sql.*;
public class ExampleForDB {
public static void main(String[] args) throws SQLException, ClassNotFoundException {
try{
Class.forName("com.mysql.jdbc.Driver");
Connection con=DriverManager.getConnection(
"jdbc:mysql://localhost:3306/******","*****","******");
System.out.print("Successful connection with MySQL!");
//here sonoo is database name, root is username and password
Statement stmt=con.createStatement();
ResultSet rs=stmt.executeQuery("select Number1 from lottery1955-00 where id=1");
System.out.println(rs.getInt(1)+" "+rs.getString(1));
con.close();
}catch (SQLException e ) {
e.printStackTrace();
}
}
}
And here you can see my error I tried so many different ways that I found here in StackOverflow but none of them worked for me, can you share your experience? see the error below
Exception in thread "main" java.lang.ClassNotFoundException: com.mysql.jdbc.Driver
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 ExampleForDB.main(ExampleForDB.java:16)