Error connecting mysql base with java

0

I use the following code to connect to mysql

 public static void main(String[] args) {

  MapeadorServicio aux = new MapeadorServicio(); 
  Auto aux1 = new Auto(0);
  Persistencia p = Persistencia.getInstancia();
  p.guardar(aux);

}

 public void guardar(Mapeador map){
    if(map.getOid()==0) insertar(map);
    else modificar(map);
}

  private void insertar(Mapeador m) {
    int oid = proximoOid();
    m.setOid(oid);
    ArrayList<String> sqls = m.getSqlInsert();
    if (!base.transaccion(sqls)){
        m.setOid(0);
    }

}

public boolean transaccion(ArrayList<String> sqls){
    try {
        conexion.setAutoCommit(false); //begin T
        for(String sql:sqls){
            if(actualizar(sql)==-1){
                conexion.rollback();
                return false;
            }
        }
        conexion.commit();
        return true;

    } catch (SQLException ex) {
            System.out.println("Error en T:" + ex.getMessage());
            return false;
    }finally{
        try {
            conexion.setAutoCommit(true); //end T
        } catch (SQLException ex) {               
        }
    }

}

private Persistencia() {
    base = BaseDatos.getInstancia();
    try {
        base.conectar("jdbc:mysql://localhost/AutosYa.com", "root", "root");
    } catch (ClassNotFoundException ex) {
        Logger.getLogger(Persistencia.class.getName()).log(Level.SEVERE, null, ex);
    } catch (InstantiationException ex) {
        Logger.getLogger(Persistencia.class.getName()).log(Level.SEVERE, null, ex);
    } catch (IllegalAccessException ex) {
        Logger.getLogger(Persistencia.class.getName()).log(Level.SEVERE, null, ex);
    }
}

The error I have is the following by console

  

Wed Dec 27 20:15:22 UYT 2017 WARN: Establishing SSL connection without server's identity verification is not recommended. According to MySQL 5.5.45+, 5.6.26+ and 5.7.6+ requirements SSL connection must be established by default if explicit option is not set. For compliance with existing applications not using SSL the verifyServerCertificate property is set to 'false'. You need either to explicitly disable SSL by setting useSSL = false, or set useSSL = true and provide truststore for server certificate verification.   Exception in thread "main" java.lang.NullPointerException   Error connecting: Access denied for user 'root' @ 'localhost' (using password: YES)       at mapeadores.MapeadorServicio.getOid (MapeadorServicio.java:46)       at persistence.Persistence.guard (Persistence.java:58)       at autosya.com.AutosYaCom.main (AutosYaCom.java:24)   /Users/usuario/Library/Caches/NetBeans/8.2/executor-snippets/run.xml:53: Java returned: 1   BUILD FAILED (total time: 0 seconds)

     

Error connecting: Access denied for user 'root' @ 'localhost' (using password: YES) at mappers.MappingService.getOid (MappingService.java:46) at

according to my MMAP

Here it looks as if I can enter with those credentials

In my project, import the JAR for the jdbl

    
asked by Bruno Sosa Fast Tag 28.12.2017 в 00:24
source

2 answers

1

Good morning:

Is it possible that you need to indicate the MySQL port in the connection ?, something like this:

base.connect ("jdbc: mysql: // localhost: 3306 / AutosYa.com", "root", "root");

    
answered by 28.12.2017 / 08:16
source
0

One solution is that you use JPA for the connection, it is relatively easy, and in my case I use it with a framework that is in netbeans called EclipseLink and I am doing great. As a brief explanation, JPA transforms the SQL statements into object-oriented programming and then you are just calling the methods you need to read, delete, and update. Investigate the subject will make things much easier to you as you can alternate between JPA and JDBC which is the most recognized to make connections between a database manager and java.

    
answered by 29.12.2017 в 01:53