I'm having a problem of displaying all the data of a column in a text file I can display only the first data, so please someone tell me what can I make to display them together in a text file.

Connection con = DriverManager.getConnection(host, uname,password);
Statement stmt = con.createStatement();
ResultSet rs = stmt.executeQuery(SQL);
while(rs.next())
{
String teller =rs.getString("name");
File file = new File("C:/Users/MY TOSHIBA/Desktop/04082012.txt");
 Writer output =null;
 output = new BufferedWriter(new FileWriter(file));
 output.write(teller);
 output.close();
    }

You create the file inside your loop, so each row of the results creates a new file and replaces the previous one. Create the file and the Writer before entering the loop and that should work better.

thanks alot for your answer it works but there is still something in which, I want to send an email with an attached file which is the file that was written, but the problem is that the file is written inside the loop so the it sends an empty file, so pelase someone answer and tell me what to do in order to receive the written file attached with the mail.

String SQL="select * from mawarid where flag=0";

Connection con = DriverManager.getConnection(host, uname,password);
Statement stmt = con.createStatement();
ResultSet rs = stmt.executeQuery(SQL);

File file = new File("C:/Users/MY TOSHIBA/Desktop/05082012.txt");
Writer output =null;
output = new BufferedWriter(new FileWriter(file));
while(rs.next())
{
String teller =rs.getString("name");

 output.write(teller);


super.mail();
 }
        output.close();
 con.close();

Maybe the email should be sent after the file is complete - ie outside the loop and after the file is closed?
(Until it's closed it's probably just sitting in a buffer in memeory, not yet written to disk.)

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.