Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public void inserir(produtos p)
- {
- List<produtos> lst = new LinkedList();
- String sql = "insert into produto (id_produto, descricao, valor, estoque) values (nextval('produto_seq'),?,?,?)";
- try {
- System.out.println("sql: "+sql);
- PreparedStatement stmt = con.prepareStatement(sql, Statement.RETURN_GENERATED_KEYS);
- stmt.setString(1, p.getDescricao());
- stmt.setFloat(2, p.getValor());
- stmt.setInt(3, p.getEstoque());
- stmt.execute();
- ResultSet rs = stmt.getGeneratedKeys();
- if(rs.next())
- {
- p.setId_produto(rs.getInt(1));
- }
- }
- catch(SQLException e)
- {
- System.out.println("ocorreu um erro: "+e.getMessage());
- System.out.println("sql: "+sql);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement