0

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)
7
  • You don't have the MySQL Connector/J JDBC driver on the class path. Add it, see linked duplicate for more information. Commented May 12, 2018 at 12:19
  • Man if the existing answer in StackOverflow does not help me then can you explain me, how it is the same case? Commented May 12, 2018 at 13:17
  • Have you followed the steps in this answer? It exactly addresses your problem (specifically step 2). In any case, I have added two other questions that address the same problem. Commented May 12, 2018 at 15:15
  • I solved my problem and it was not the same as it is written in the examples you gave me, and because you closed my question now no one will understand how to solve easily the problem that I got. Sometimes the moderators are too fast with their decisions to cancel some question. Commented May 12, 2018 at 15:24
  • 1
    Well, could you describe/explain how you solved your problem, if it is really a different solution I'll reopen it so you can add your own answer. Also, I'm not a moderator, moderators have a diamond next to their name. Commented May 12, 2018 at 15:42

0

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.