Skip to Main Content

Java Development Tools

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Writing Query output to a file from a Java program

98322Mar 30 2005 — edited Mar 31 2005
Hello,

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
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Apr 28 2005
Added on Mar 30 2005
4 comments
2,154 views