I have a class BancoDeDados
and it contains two methods: conexao
and addDespesa
. The conexao
method connects to my local database. The addDespesa
method adds values
to one of my tables, but it can not "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);
}
}