Ecco il codice ripulito e e corretto
Codice PHP:
protected void processRequest(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException, SQLException, ParseException {
response.setContentType("text/html;charset=UTF-8");
PrintWriter out = response.getWriter();
Connection con = null;
String sql = null;
PreparedStatement inserisciCommento = null;
try {
Class.forName("com.mysql.jdbc.Driver");
}
catch(java.lang.ClassNotFoundException ex){
System.err.print(ex);
}
try{
String autore = request.getParameter("autore");
String titolo = request.getParameter("titolo");
String articolo = request.getParameter("articolo");
String url = ("jdbc:ysql://localhost/blog");
String usr = "root";
String pwd = "francesco";
con = DriverManager.getConnection(url, usr, pwd);
sql = ("INSERT INTO articoli (art_autore,art_titolo,art_articolo,) VALUES ((?),(?),(?))");
inserisciCommento = con.prepareStatement(sql);
inserisciCommento.setString(1,autore);
inserisciCommento.setString(2,titolo);
inserisciCommento.setString(3,articolo);
int inserimento = inserisciCommento.executeUpdate();
if(inserimento == 1){
out.println("Inserimento Effettuato");
}
else{
out.println("Inserimento Non Effettuato");
}
}
catch(SQLException sqlexx){
System.err.println(sqlexx.getMessage());
}
/* TODO output your page here
out.println("<html>");
out.println("<head>");
out.println("<title>Servlet inserisciCommento</title>");
out.println("</head>");
out.println("<body>");
out.println("<h1>Servlet inserisciCommento at " + request.getContextPath () + "</h1>");
out.println("</body>");
out.println("</html>");
*/
finally {
try{
if(inserisciCommento!= null){
inserisciCommento.close();
}
if(con!=null){
con.close();
}
}
catch(SQLException sqlexxx){
System.err.print(sqlexxx.getMessage());
}
out.close();
}
Niente da fare. Non funge.. suggerimenti?