[RESOLVIDO] banco de dados

3 respostas
Lucas_Romeo

TENHO O SEGUINTE CODIGO

public static void main(String[] args) throws Exception, SQLException {
		
		Class.forName("org.postgresql.Driver");
		Connection connection = DriverManager.getConnection("jdbc:postgresql://piedade/emailrehagro", "postgres", "gre4POL2");
		connection.setAutoCommit(false);
		
		String sqlInsertEmail = "insert into email (cdemail, email) values (?)";
		PreparedStatement statementInsertEmail = connection.prepareStatement(sqlInsertEmail);
		
		File file = new File("C:\Para tirar do W3.dbx");
		FileReader fr = new FileReader(file);
		BufferedReader bf = new BufferedReader(fr);

		while (bf.ready()) {

			String line = bf.readLine();


			if (enderecosEmail(line) != null && !enderecosEmail(line).equals("[email removido]") && !enderecosEmail(line).equals("[email removido]")) {
				System.out.println(enderecosEmail(line));
				statementInsertEmail.setString(1, enderecosEmail(line));
				
			}
//			}
		}
	}
}

ELE RODA.... MAS NAUM SALVA NENHUM DADO (EMAIL), NO BANCO DE DADOS.... ALGUEM SBE O PQ??

O ARQUIVO EXISTE... TEM VARIOS EMAILS NELE, ELE SÓ NAO ESTÁ SALVANDO MESMO. EMAIL NO BANCO ESTA COMO VARCHAR.

3 Respostas

Amanweb

Você deve chamar o método executeUpdate() da classe PreparedStatement

L
connection.setAutoCommit(false);

como a opcao esta false, vc tem que chamar o commit manualmente

Lucas_Romeo

consegui :p

o final fiko assim

while (bf.ready()) {

			String line = bf.readLine();
			if (enderecosEmail(line) != null && !enderecosEmail(line).equals("[email removido]") && !enderecosEmail(line).equals("[email removido]")) {
				System.out.println(enderecosEmail(line));
				statementInsertEmail.setString(1, enderecosEmail(line));
				statementInsertEmail.execute();
			}
		}
		statementInsertEmail.close();
		connection.commit();
		connection.close();
		bf.close();

realmente estava faltando o statement....

vlws!! =D

Criado 19 de fevereiro de 2008
Ultima resposta 19 de fev. de 2008
Respostas 3
Participantes 3