Jump to content
Fórum Script Brasil
  • 0

resultado em TXT


Guest
 Share

Question

Opa pessoal boa tarde

 

Preciso de uma ajuda, tenho este select abaixo e gostaria que ele em vez de exibir na tela gerasse um arquivo txt com todos os dados e possivel

 

 

 

Class.forName( "org.postgresql.Driver" );
Connection cn = DriverManager.getConnection( "jdbc:postgresql://10.0.0.10:5432/teste", "postgres", "teste" );
cn.setAutoCommit( true );

Statement st = cn.createStatement();    
ResultSet rs = st.executeQuery( "SELECT * from funcionarios order by funcionarios" );
while( rs.next() )
{
    out.println( "CPF = " + rs.getString( "cpfatendente" ) );
}
rs.close();
st.close();
cn.close();

Link to comment
Share on other sites

1 answer to this question

Recommended Posts

  • 0
Class.forName( "org.postgresql.Driver" );
Connection cn = DriverManager.getConnection( "jdbc:postgresql://10.0.0.10:5432/teste", "postgres", "teste" );
cn.setAutoCommit( true );

Statement st = cn.createStatement();    
ResultSet rs = st.executeQuery( "SELECT * from funcionarios order by funcionarios" );
BufferedWriter bw = new BufferedWriter(new FileWriter("arquivo.txt", true));

while( rs.next() )
{
    String cpf = rs.getString( "cpfatendente" );
    bw.write(cpf + "\n");
    out.println( "CPF = " + cpf );
}

bw.close();
rs.close();
st.close();
cn.close();

Tente assim...

Edited by leonardosc
Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Answer this question...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

 Share

  • Forum Statistics

    • Total Topics
      149.6k
    • Total Posts
      646.2k
×
×
  • Create New...