Come noto, con il seguente codice posso visualizzare dei record contenuto in un database MySQL:
Come posso visualizzare ad esempio i recor a 5 alla volota?codice:<% String connectionURL = "jdbc:mysql://localhost:3306/teachingmachine?user=;password="; Connection connection = null; Statement statement = null; ResultSet rs = null; try{ //Avvio la connessione al db mysql Class.forName("com.mysql.jdbc.Driver").newInstance(); connection = DriverManager.getConnection(connectionURL, "", ""); } catch (ClassNotFoundException e){ out.println("Impossibile caricare il driver MySQL: "+ e); } %> <table border="0" width="100%"> <tr> <td width="33%"></td> <td width="23%"> <p align="center">Materia</td> <td width="44%">Serie di ripasso</td> </tr> <% try{ //Istanzio e inizializzo l'oggetto st di tipo Statement statement = connection.createStatement(); //Istanzio e inizializzo l'oggetto rs di tipo ResultSet rs = statement.executeQuery("SELECT * FROM materie"); while(rs.next()){ %> <tr> <td width="33%"></td> <td width="23%"> [img]img/CHECK.GIF[/img] <%=rs.getString(2)%> </td> <td width="44%"> <%=rs.getString(3)%>,<%=rs.getString(4)%>,<%=rs.getString(5)%>,<%=rs.getString(6)%> </td> </tr> <% }//while %> </table> <% //chiusura delle connessioni rs.close(); statement.close(); connection.close(); } catch (SQLException e){ out.println("Errore SQL: "+ e); } %>

Rispondi quotando