Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / General / June 2005

Tip: Looking for answers? Try searching our database.

Printwriter limitations?

Thread view: 
philip.kluss@gmail.com - 27 May 2005 21:30 GMT
Greetings,

I'm writing a little job to do a SQL query and dump the data into a
flatfile.  For some reason it cuts off before finishing the whole
thing.  I don't know of any limitations on the objects that I'm using,
but maybe I've missed something.  Here is the code..

--------------------------
import java.io.*;
import java.sql.*;

public class getList {
    public static void main(String[] args) {
        try {
            Class.forName("com.microsoft.jdbc.sqlserver.SQLServerDriver");

            String url =
"jdbc:Microsoft:sqlserver://hal:1433;DatabaseName=Test";
           Connection conn =
DriverManager.getConnection(url,"thisis","superfake");

           String query = "select ITEMNMBR from IV00101";
           Statement stmt = conn.createStatement();
           ResultSet rs = stmt.executeQuery(query);

           int rows = 0;

            PrintWriter out = new PrintWriter(new
FileOutputStream("FullItemList.doc"));
            while (rs.next()) {
                  String itemNumber = rs.getString("ITEMNMBR");
                 out.println(itemNumber);
                 rows++;
            }

            System.out.println(rows + " rows");

       } catch (Exception e) {
           System.err.println(e);
       }
   }
}

----------------------------------

As I said, it pretends to have returned all the rows and finishes
running without an exception, but the output file cuts off in the
middle of the same line every time.

Thanks for your time and thought.

-Phil
Roland - 27 May 2005 22:01 GMT
> Greetings,
>
[quoted text clipped - 48 lines]
>
> -Phil

Try to close the PrintWriter properly before ending the program.

The constructor PrintWriter(InputStream) creates a PrintWriter that does
not automatically flush when println() is invoked.
Signature

Regards,

Roland de Ruiter
  ___      ___
 /__/ w_/ /__/
/  \ /_/ /  \

pk - 01 Jun 2005 18:06 GMT
Thank you very much, your answer was right on.


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.