Hi there,
I have java program that makes JDBC connection and reads through a table, write a column in text file, after each column puts delimiter "|"and after each row prints in the next line.
This is the code below.
public void queryRecords() {
Statement stmt = null;
ResultSet rset = null;
try {
stmt = con.createStatement();
int numRows = 0;
File file = new File("/tmp/temp.txt");
FileWriter writer = new FileWriter(file, false);
BufferedWriter pw = new BufferedWriter(writer);
rset = stmt.executeQuery("SELECT * FROM mytable");
ResultSetMetaData rsmd = rset.getMetaData();
int colCount = rsmd.getColumnCount();
while (rset.next()) {
for (int i = 1;i <= colCount; i++) {
String st = rsmd.getColumnTypeName(i);
if (st.equals("DATE")) {
Date d1 = rset.getTimestamp(i);
pw.write(d1 + "|");
} else {
Object o1 = rset.getObject(i);
if (o1 != null) {
pw.write(o1 + DELIM);
} else {
pw.write(DELIM);
}
}
}
pw.newLine();
}
pw.close();
rset.close();
stmt.close();
When i open this Temp.txt file in notepad i see ascii character 129 (rectangular box) instead of the new line. But when i print the file i have each row in a separate line.
Why could this be happening??
Please help...