Pessoal, estou usando essa classe para inserir
porem quando tento inserir da sql exception
Classepublic class GerenciaBanco {
private static final String URL = "jdbc:mysql://ip:3306/teste_java";
private static final String DRIVER = "com.mysql.jdbc.Driver";
private static final String USUARIO = "bases";
private static final String SENHA = "senha";
private String numero;
private String sql;
private Connection conn;
/** Creates a new instance of GerenciaBanco */
public GerenciaBanco(){
sql = new String();
numero = new String();
}
public void Conectar_banco(String sql) throws SQLException,ClassNotFoundException {
try{
Class.forName(DRIVER);
Connection conn = DriverManager.getConnection(URL,USUARIO, SENHA);
Statement tabela = conn.createStatement(); // criando instancia de inserção.
tabela.execute(sql);
tabela.close();
}
catch(ClassNotFoundException e){
System.out.println("Erro ao acessar o banco");
}
catch (SQLException e){
System.out.println("Erro de Sql");
}
}
public void inserir_numeros(ElementoDownload elemento) throws SQLException, ClassNotFoundException{
String sql = "INSERT INTO GERENCIA (chave) values ('"+elemento.pegaChave()+"')"; // String de inserção.
this.Conectar_banco(sql);
}
}
Alguem sabe o que estou errando ?