I need a little help, I'm a beginner. I have to send a txt file that I open in netbeans to a PgAdmin table.
If you see the code, you will understand me. I tried to put my method that shows the txt file in INSERT but it did not work. I do not know the right way to do this. the table loads numeric, date, and 6 numeric columns. In that order, thank you.
public class ConexaoTexte {
public static void main(String[] args) {
try {
String url = "jdbc:postgresql://localhost:5432/teste";
String usuario = "postgres";
String senha = "123456";
Arquivo arquivo = new Arquivo();
Class.forName("org.postgresql.Driver");
Connection con;
con = DriverManager.getConnection(url, usuario, senha);
System.out.println("Conexão realizada com sucesso.");
Statement s = con.createStatement();
//esse metodo "subirArquivo" mostra o meu arquivo texto na tela.
arquivo.subirArquivo();
//porem como fazer para inserir ao banco??
s.executeUpdate("INSERT INTO resultados VALUES ('1','09-11-2016','1','2';'3')");
con.close();
} catch (ClassNotFoundException ex) {
System.out.println("Não foi possível encontrar a Classe!");
} catch (SQLException ex) {
}
}
}
// the class to show my text file.
public class File {
public void subirArquivo() {
try (Scanner ler = new Scanner(new File("c:/teste.txt"))) {
while (ler.hasNext()) {
System.out.println(ler.nextLine());
}
} catch (IOException e) {
System.err.println("Falha ao ler arquivo!");
}
}
}