Advertisement
Guest User

Untitled

a guest
Nov 9th, 2016
78
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.18 KB | None | 0 0
  1. public class ConexaoTexte {
  2.  
  3. public static void main(String[] args) {
  4. try {
  5.  
  6. String url = "jdbc:postgresql://localhost:5432/teste";
  7. String usuario = "postgres";
  8. String senha = "123456";
  9.  
  10. Arquivo arquivo = new Arquivo();
  11.  
  12. Class.forName("org.postgresql.Driver");
  13.  
  14. Connection con;
  15.  
  16. con = DriverManager.getConnection(url, usuario, senha);
  17.  
  18. System.out.println("Conexão realizada com sucesso.");
  19.  
  20. Statement s = con.createStatement();
  21.  
  22. //esse metodo "subirArquivo" mostra o meu arquivo texto na tela.
  23. arquivo.subirArquivo();
  24.  
  25. //porem como fazer para inserir ao banco??
  26. s.executeUpdate("INSERT INTO resultados VALUES ('1','09-11-2016','1','2';'3')");
  27.  
  28. con.close();
  29.  
  30. } catch (ClassNotFoundException ex) {
  31. System.out.println("Não foi possível encontrar a Classe!");
  32. } catch (SQLException ex) {
  33. }
  34. }
  35.  
  36. public void subirArquivo() {
  37.  
  38. try (Scanner ler = new Scanner(new File("c:/teste.txt"))) {
  39. while (ler.hasNext()) {
  40. System.out.println(ler.nextLine());
  41. }
  42. } catch (IOException e) {
  43. System.err.println("Falha ao ler arquivo!");
  44. }
  45. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement