import java.sql.Connection;
import java.sql.SQLException;
import java.sql.Statement;

public class TestaInsercao {

  public static void main(String[] args) throws SQLException {
    Connection connection = Database.getConnection();
    Statement statement = connection.createStatement();
    boolean resultado = statement.execute("insert into Produto (nome, descricao) values('Notebook', 'Notebook i5'", Statement.RETURN_GENERATE_KEYS);
    System.out.println(resultado);

    ResultSet resultSet = statement.getGeneratedKeys();
    while(resultSet.next()) {
      String id = resultSet.getString("id");
      System.out.println(id + " gerado");
    }

    statement.close();
    connection.close();
  }

}

@@ -172,16 +172,87 @@
 ption %7B%0A
+    String nome = %22Notebook%22;%0A    String descricao = %22  Notebook i5%22;%0A%0A
     Conn
@@ -297,20 +297,100 @@
 tion();%0A
+%0A
     
+String sql = %22insert into Produto (nome, descricao) values(?, ?)%22;%0A    Prepared
 Statemen
@@ -418,13 +418,14 @@
 ion.
-creat
+prepar
 eSta
@@ -435,157 +435,170 @@
 ent(
-);%0A    boolean resultado = statement.execute(%22insert into Produto (nome, descricao) values('Notebook', 'Notebook i5'%22, Statement.RETURN_GENERATE_KEYS
+sql,%0A        Statement.RETURN_GENERATE_KEYS);%0A    statement.setString(1, nome);%0A    statement.setString(2, descricao);%0A%0A    boolean resultado = statement.execute(
 );%0A 
@@ -812,16 +812,39 @@
 %0A    %7D%0A%0A
+    resultSet.close();%0A
     stat

Insert new files, Alura, JDBC e banco de dados em Java, Aula 3