edit: I want to add values to a table (paziente) working with a view of that table (viewPaziente) and not directly the table.
edit2: Found a stupid mistake in the code, now it does give me an error, but it is not helping:
org.h2.jdbc.JdbcSQLException: Feature not supported: "VIEW"; SQL statement: INSERT INTO "viewPaziente" values(?,?,?,?,?,?,?,?,?,?,?,?,?) [50100-147]
Is it possible to insert a row in a view of a table?
I mean... I have a table "paziente" with many fields, I've created a view of Paziente and I want to add a row to paziente through the view. Is it possible to do this in H2?
I'm using the following code
public static boolean AddAnagrafica(String nome, String cognome,
String data, String telefono, String email,String codiceFiscale, boolean isDonna, String indirizzo, String citta,
String provincia, String cap, String paese ){
Connection conn=null;
try {
conn = getConnection();
PreparedStatement st = conn.prepareStatement("INSERT INTO \"viewPaziente\" values(?,?,?,?,?,?,?,?,?,?,?,?,?)");
st.setInt(1, new Random().nextInt());
st.setString(2,nome);
st.setString(3,cognome);
st.setString(4,data);
st.setString(5,telefono);
st.setString(6,email);
st.setString(7,codiceFiscale);
st.setBoolean(8,isDonna);
st.setString(9,indirizzo);
st.setString(10,citta);
st.setString(11,provincia);
st.setString(12,cap);
st.setString(13,paese);
st.executeUpdate();
} catch (SQLException e) {
e.printStackTrace();
}
return false;
}
In H2, views are not updatable by default. To make them updatable, you need to use an 'instead of' trigger. An example on how to do that available in the H2 source repository.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With