1
I have a class BancoDeDados and it contains two methods: conexao and addDespesa. The method conexao connects to my local database. The method addDespesa adds values in one of my tables, but cannot "catch" the variable of type Statement whose name is mysql.
public class BancoDeDados {
public void conexao(){
try {
System.out.println("Conectando ao Banco de Dados..");
Class.forName("com.mysql.jdbc.Driver");
Connection conexao = DriverManager.getConnection("jdbc:mysql://localhost:3306/despesas?useSSL=true","root","local");
Statement mysql = conexao.createStatement();
System.out.println("Conectado. \n");
} catch (ClassNotFoundException | SQLException e) {
System.out.println("Erro na Conexão");
}
}
public void addDespesa(String addDesp){
String sqlInsert;
sqlInsert = "insert into tipo_de_despesa(descricao) values ('"+addDesp+"')";
mysql.execute(sqlInsert);
}
}