1

I'm following a tutorial on JDBC and I wrote this code:

package jc;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
import java.util.logging.Level;
import java.util.logging.Logger;
import java.sql.Statement;
import java.sql.ResultSet;

public class Jc {

    public static void main(String[] args) {
        Jc exec = new Jc();
        exec.createConnection();
    }

    void createConnection(){
        try {
            Class.forName("com.mysql.jdbc.Driver");
            System.out.println("done");
            Connection con = DriverManager.getConnection("jdbc:mysql://localhost:3306/adherants", "root", "user");
            System.out.println("done");
            Statement stmt = con.createStatement();
            System.out.println("done");
            ResultSet rs = stmt.executeQuery("SELECT * FROM persone");
            System.out.println("done");
            while(rs.next()){
                String CIN = rs.getString("CIN");
                System.out.println(CIN);
            }
            System.out.println("done");
        } catch (ClassNotFoundException ex) {
            Logger.getLogger(Jc.class.getName()).log(Level.SEVERE, null, ex);
        } catch (SQLException ex) {
            Logger.getLogger(Jc.class.getName()).log(Level.SEVERE, null, ex);
        }
    }

}

However, I always get these output messages: that's what i see in the output

More specifications:

  1. IDE: Apache NetBeans 11.3
  2. database management system: MySQL
Mark Rotteveel
  • 100,966
  • 191
  • 140
  • 197
biridev
  • 37
  • 5
  • 3
    You need to download the [mysql connector/j](https://dev.mysql.com/downloads/connector/j/5.1.html) from mysql. And then you need to install it. And then you need to add the [jar as a run-time dependency](https://stackoverflow.com/q/4879903/2970947) to your project. – Elliott Frisch May 02 '20 at 22:27
  • it worked, thanks for the help. i don't know how to highlight your comment as a good answer though. – biridev May 03 '20 at 01:43

0 Answers0