I am trying to insert a new record using jdbc. Everything looks fine, I have no exception, but the new record is not inserted into the table. The select rule works correctly.
public Connection getConnection(){ Connection conn=null; try { Class.forName("org.postgresql.Driver"); } catch (ClassNotFoundException e) { e.printStackTrace(); } try { conn = DriverManager.getConnection(url); conn.setAutoCommit(true); } catch (SQLException e) { e.printStackTrace(); } return conn; } public void insertDish(String name, float mass, float price, String description,int pizzeria_id) { String insertStr = "insert into \"Dish\"(name,mass,price,description,pizzeria_id) values("+"'"+name+"'"+", "+mass+", "+price+", "+"'"+description+"'"+", "+pizzeria_id+")"; Connection conn = getConnection(); try { Statement sql = conn.createStatement(); sql.executeUpdate(insertStr); sql.close(); conn.close(); } catch (SQLException e) { e.printStackTrace(); } }
What could be wrong?
sunny source share