JDBC connection in Eclipse Neon

1

I need help adding the JDBC driver to my project made in Eclipse Neon version. If possible, pass on a connection class for testing.

    
asked by anonymous 26.02.2017 / 16:27

1 answer

0

Download the .jar of the mysql connector and add to the Java build patch.

Follow the connection class.

  • method no return connect ()

  • main method to test the connect () method call

 
    public class Conexao {
      public static void conectar() {
        try {
            Class.forName("com.mysql.jdbc.Driver");
            System.out.println("Carregou o Driver");
            String url = "jdbc:mysql://localhost:3306/seu_banco";
            String user = "seu_usuario";
            String password = "sua_senha";
            try {
                con = DriverManager.getConnection(url, user, password);
                System.out.println("Conectou");
                stm = con.createStatement();
            } catch (SQLException ex) {
                System.out.println(" Não Conectou");
                Logger.getLogger(Conexao.class.getName()).log(Level.SEVERE, null, ex);
            }
        } catch (ClassNotFoundException ex) {
            System.out.println("Não Carregou o Driver");
            Logger.getLogger(Conexao.class.getName()).log(Level.SEVERE, null, ex);
        }
    }       
      public static void main(String[] args) {
          conectar();
      }
    }
 
    
02.03.2017 / 20:26