Mysql
 sql >> Database >  >> RDS >> Mysql

Ricevere un errore durante il tentativo di riempire il menu a discesa HTML con i dati di MySQL in Java?

cambia la tua pagina html in jsp e segui questo codice:

<%@page import="java.sql.*"%>
<html>
<form name="form" method="post" >
<b>Select a country:</b> </td>
<select name="sel"><option value=""><---Select---></option>
<%
Class.forName("com.mysql.jdbc.Driver").newInstance();
String connectionURL = "jdbc:mysql://localhost:3306/test";
Connection connection= DriverManager.getConnection('jdbc:mysql://192.168.1.104:3306/networkmonitoring','mohsin','123456');");
PreparedStatement psmnt = connection.prepareStatement("select objecttype_name from network_objecttype ");
ResultSet results = psmnt.executeQuery();
while(results.next()){
String name = results.getString('objecttype_name');
String id = results.getString('objecttype_name');
%><option value="<%= name %>"><%=name%></option>
<%} results.close(); psmnt.close(); %>
</select><br>
</form>