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:
More specifications:
- IDE: Apache NetBeans 11.3
- database management system: MySQL