import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.Scanner;
public class AdicionarProduto {
public static void main(String[] args) throws SQLException {
Scanner scan = new Scanner(System.in);
ConnectionFactory factory = new ConnectionFactory();
Connection connection = factory.recuperarConexao();
String nome = scan.next();
String descricao = scan.next();
PreparedStatement stm = connection.prepareStatement("INSERT INTO PRODUTO (nome, descricao) VALUES (?, ?)",
PreparedStatement.RETURN_GENERATED_KEYS);
stm.setString(1, nome);
stm.setString(2, descricao);
ResultSet rst = stm.getGeneratedKeys();
stm.execute();
while (rst.next()) {
String produto = rst.getString(nome);
System.out.println(produto + " adicionado");
}
scan.close();
}
}