Allora ho un metodo creaSQL() che crea una stringa SQL, stringa perfettamente funzionante perchè l'ho incollata direttamente nella finesta MySQL ed effettua l'upgrade:
Supponiamo quindi che quindi il metodo creaSQL sia così:codice:INSERT INTO q (id_u, id_q, id_d, p) VALUES(1, 4, 2, 1), (1, 4, 3, 2), (1, 4, 1, 3)
Fin qui sembrerebbe tutto ok, ora all'interno della servlet avrò un altro metodo che prende la stringa sql e la deve eseguire:codice:protected String creaSQL(int id_usr) throws ClassNotFoundException, SQLException { String sql = "INSERT INTO q (id_u, id_q, id_d, p) VALUES(1, 4, 2, 1), (1, 4, 3, 2), (1, 4, 1, 3)"; return sql; }
Ma in return nn mi da nulla, manco "dentro". Se invece commento tutta la parte di codice in rosso, la parola "dentro" mi viene restituita.codice:protected String execQuery(int id_usr) throws ClassNotFoundException, SQLException { String msg="dentro"; String sql = creaSQL(id_usr); Class.forName("com.mysql.jdbc.Driver"); Connection conn = DriverManager.getConnection("url","user","pass"); Statement st = conn.createStatement(); int query = st.executeUpdate(sql); if (query==1) { msg = "OK..."; } else { msg = "C'è stato un errore!!!"; } //conn.close(); return msg; }
Dove sbaglio???

Rispondi quotando
