Ho cambiato alcune cose, non mi da errori di compilazione, ma non funziona l'inserimento dei dati nel database.
Il file html è diventato jsp ed è il seguente:
<%@ Language=java%>
<html>
<head>
<title></title>
</head>
<body>
<center><table>
<form name="formComponenti" method=POST >
<tr><td>
<input type=text name="nome" value="">
<%
String nome=request.getParameter("nome");
%>
</td></tr>
<tr><td>
<input type=text name="cognome" value="">
<%
String cognome=request.getParameter("cognome");
%>
</td></tr>
<tr><td>
<input type=text name="città">
<%
String città=request.getParameter("città");
%>
</td></tr>
<tr><td>
<input type=submit value="inserisci">
</td></tr>
</form>
</table>
</body>
</html>
nel file per la connessione c'è questo codice:
import java.sql.*;
class Esecuzione extends Connessione{
public static void main(String args[]) {
Connection con=null;
PreparedStatement st=null;
ResultSet rs=null;
try {
con=Connessione.getConnection();
String sql="INSERT INTO (nome, cognome, indirizzo) VALUES (?,?,?)";
st.setString(1, "nome");
st.setString(2, "cognome");
st.setString(3, "città");
st=con.prepareStatement(sql);
st.execute();
} catch (Exception e) {
System.out.println ("Database error " + e );
} finally {
try {
if (rs != null)
rs.close();
if (st != null)
st.close();
if (con != null)
con.close();
} catch (Exception e2) {
System.out.println("Unable to close: " +e2);
}
}
}
}
Qualcuno sa dirmi perchè non riesce a popolare il database?
E poi, scusate l'ignoranza, ma io apro il file jsp con explorer, non è che serve il web server?