Printwriter limitations?

P

philip.kluss

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
 
R

Roland

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_/ /__/
/ \ /_/ / \
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,995
Messages
2,570,228
Members
46,818
Latest member
SapanaCarpetStudio

Latest Threads

Top