Printwriter limitations?

Discussion in 'Java' started by philip.kluss@gmail.com, May 27, 2005.

  1. Guest

    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
     
    , May 27, 2005
    #1
    1. Advertising

  2. Roland Guest

    On 27-5-2005 22:30, wrote:
    > 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
    >

    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.
    --
    Regards,

    Roland de Ruiter
    ___ ___
    /__/ w_/ /__/
    / \ /_/ / \
     
    Roland, May 27, 2005
    #2
    1. Advertising

  3. pk Guest

    Thank you very much, your answer was right on.
     
    pk, Jun 1, 2005
    #3
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Oz Levanon
    Replies:
    1
    Views:
    2,113
  2. Houman
    Replies:
    2
    Views:
    710
    Frank
    Aug 18, 2004
  3. Sharp
    Replies:
    5
    Views:
    403
    Paul Lutus
    Oct 15, 2004
  4. Lars Willich
    Replies:
    0
    Views:
    601
    Lars Willich
    Jan 28, 2005
  5. CamT
    Replies:
    1
    Views:
    4,417
    Oscar kind
    Mar 16, 2005
Loading...

Share This Page