Writing Query output to a file from a Java program
98322Mar 30 2005 — edited Mar 31 2005Hello,
Thank you in advance! I have a piece of simple Java code which works fine in getting the data from a database. However, I would like to send the same output to a file. Can you please help?
Here is the code:
*************************
import java.sql.*;
import java.sql.SQLException.*;
import oracle.jdbc.driver.*;
class JdbcTest {
public static void main (String args []) throws SQLException {
// Load Oracle driver
DriverManager.registerDriver(new oracle.jdbc.driver.OracleDriver());
// Connect to the local database
Connection conn = DriverManager.getConnection ("jdbc:oracle:thin:@host:1521:db","hr", "hr");
// Query the employee names
Statement stmt = conn.createStatement ();
ResultSet rset = stmt.executeQuery ("SELECT job_id, job_title FROM jobs");
// Print the name out
while (rset.next ())
System.out.println (rset.getString (1) + " " + rset.getString(2));
//close the result set, statement, and the connection
rset.close();
stmt.close();
conn.close();
}
}
********************
Thanks again,
Kishore