Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- 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) {
- }
- }
- 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!");
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement