Ciao, ho creato un jsp per lavorare coi database dal server, uso Glassfish v3 Domain, ho provato anche con Glassfish 3 prelude e tomcat ma i problemi sono gli stessi. Il codice è il seguente:
Ora, il problema sta nella rigacodice:<%-- Document : index Created on : 4-nov-2011, 10.09.32 Author : UTENTE --%> <%@page contentType="text/html" pageEncoding="UTF-8"%> <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <%@page import="java.sql.*"%> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> <title>JSP Page</title> </head> <% Statement stmt = null; try { Class.forName("com.mysql.jdbc.Driver"); String connectionUrl = "jdbc:mysql://localhost/dbanagrafica?user=admin&password=pass"; Connection con = DriverManager.getConnection(connectionUrl);out.println("la connessione funge"); stmt=con.createStatement(); stmt.executeUpdate("INSERT INTO tab1(ciao0) VALUES ('ma che bella scoperta')"); } catch (SQLException e) { out.println("SQL Exception: "+ e.toString()); } catch (ClassNotFoundException cE) { out.println("Class Not Found Exception: "+ cE.toString()); } %> </html>
Lo eseguo e mi dà come errore: SQL Exception: java.sql.SQLException: Field 'ciao1' doesn't have a default value.codice:stmt.executeUpdate("INSERT INTO tab1(ciao0) VALUES ('ma che bella scoperta')");
Il che è normale, perchè non ho inizializzato i campi, ma allo stesso tempo è strano perchè gli sto chiedendo di inizializzare, non di leggere...
Su phpMyAdmin, invece, selezionando la tabella, andando nella scheda "SQL" ed eseguendo la query da lì tutto risulta giusto e mi trovo la mia stringa dentro la tabella.
Suggerimenti? Grazie. ciao!

Rispondi quotando