JDBC connection in Eclipse Neon

Asked

Viewed 554 times

1

I need help adding the JDBC driver to my project done in the Eclipse Neon version. If possible pass a connection class to test.

1 answer

0


Download the mysql Connector . jar and add to the Java build patch.

Follows Class of connection.

  • method no return connect()

  • main method to test the call of the connect method()

 
    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();
      }
    }
 
  • Managed to solve?

Browser other questions tagged

You are not signed in. Login or sign up in order to post.