martedì 13 aprile 2010

Alcuni metodi della nostra classe utilitaria

Class Utl extends HttpServlet{
// Questo metodo inserisce gli apostrofi singoli a valori in SQL

static String apos(String a){
a= " ' " + a + " ' ";
return a;
}
}
Class Utl extends HttpServlet{
// Questo metodo inserisce le virgole

static String comma(String [] valori){
int i = 1; String v = valori[o];
while (i < valori.length){
v= v + " , " + valori [i],
i++;
}
return v;
}
}

Esercizio per mercoledi 14 aprile

Class InsertInto extends HttpServlet{

//effettuare un insert into da una pagina html con 3 input dentro alla form nome,cognome,voto

void doGet(HttpServletRequest req,
HttpServletResponse res) Throws ServletException,IOException{
String nomeTabella = "Studenti";
String nome = Utl.comma(Utl.apos(req.getParameter("nome")));
String cognome = Utl.comma(Utl.apos(req.getParameter("cognome")));
String voto = Utl.comma(Utl.apos(req.getParameter("voto")));
String insertInto = "INSERT INTO" + nomeTabella "VALUES (" + nome + cognome + voto + ")";
}
}

Nessun commento: