import java.sql.*;
class Abdon1{
//Informações para a conexão
private final static String driver = “sun.jdbc.odbc.JdbcOdbcDriver”;
private final static String url = “jdbc:odbc:AGENDA”;
private final static String username ="";
private final static String password ="";
//Ambiente para conexão
private Connection con;
private Statement stmt;
private ResultSet rs;
//Definição de dados
private String nome = null;
private String telefone = null;
//Abrir Banco de Dados
public void openDB(){
try{
Class.forName(driver);
con = DriverManager.getConnection(url, username, password);
stmt = con.createStatement();
System.out.println("Conexao estabelecida com sucesso ");
}//end try
catch(ClassNotFoundException e){
System.out.println("Erro ao carregar JDBC/ODBC pois: "+e);
System.exit(1);
}//end catch
catch(SQLException e){
System.out.println("Nao foi possivel estabelicer conexao pois: "+e);
}//end catch
}//end openDB
public void setNome(String a){
nome = a;
}//end setNome
public void setTelefone(String b){
telefone = b;
}//end setTelefone
//Metodo que grava os dados no Banco de dados
public void gravaDados(){
System.out.println(nome);
String query = "INSERT INTO AGENDA(NOME, TELEFONE) VALUES ("+nome+","+telefone+")";
try{
System.out.println("Inserindo dados...");
stmt.executeUpdate(query);
}//end try
catch(SQLException e){
System.out.println("Erro ao inserir dados pois: "+e);
}//end catch
}//end gravaDados
public static void main(String args[]){
Abdon1 a = new Abdon1();
a.openDB();
a.nome="Ovelha";
a.telefone="1111111";
a.gravaDados();
}//end main
}//end class Jbd
Pegando neste exemplo, como eu faria se n quisesse adicionar os dados (que ja estão defenidos no programa) mas sim, colocar o que o usuario escreveu? ou seja recebe-los