1
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 n worked. I don’t know the right way to do this. the table loads Numeric columns, date and 6 more Nouric. In that order I 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 display 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!");
}
}
}
Question, do you want to send what to the database? File name only? To then fetch it from the bank to then open the file from a specific directory?
– R.Santos
Hello, I got it. It was a file with several names and numbers. I just needed to create a loop to then distribute to the columns of my table.Vlw
– João Pedro Henrique Pereira
It is interesting that you post an answer to how you managed to solve your problem so that the next one who has this same difficulty, is helped by your answer :)
– R.Santos