Do you not upload the data from my database to my jsp?

0

The database is locally I understand that it is placed the libraries are already placed from jdbc and the jar of mysql but does not pull the data

    
asked by JP Ramirez 14.12.2016 в 18:31
source

1 answer

2

You have three very important mistakes:

  • The end of the try/catch is to show the stacktrace to know where an exception occurs and why it happens.
  • A colon is missing ":" after jdbc:mysql
  • There are spaces in the strings both in the connection URL and in the name of the class that brings you and starts the JDBC library.
  • Your try/catch does nothing or shows nothing if you catch a Exception ..

    Try changing the connection url of

    jdbc:mysql//localhost/db?etc...
    

    a

    jdbc:mysql://localhost/db?etc...
    

    Normally the port should also be specified:

    jdbc:mysql://localhost:3306/db?etc...
    

    If this does not solve your error, (and even if you solve it!) add:

    e.printStackTrace();
    

    At your catch(Exception e){ .... aca ...}

    If you leave the url uncorrected you will get a

      

    java.sql.SQLException: No suitable driver found for   jdbc: mysql // localhost / etc ...

    Important not to leave spaces in the url, otherwise you will also get this exception

    If you leave the spaces in forName("[espacio]com.mysql.jdbc.Driver") the following exception will be thrown:

      

    java.lang.ClassNotFoundException: com.mysql.jdbc.Driver

    Your final code should be something like this:

    <%
        try {
            Class.forName("com.mysql.jdbc.Driver");
            Connection con = DriverManager.getConnection(" jdbc:mysql://localhost/cursosjsp?user=root");
            Statement st = con.createStatement();
            ResultSet rs = st.executeQuery("select * from usuarios");
    
            while (rs.next()) {
                // etc ...
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
    %>
    
        
    answered by 15.12.2016 / 04:54
    source