Results 1 to 3 of 3
  1. #1
    matpj is offline Member
    Join Date
    Sep 2008
    Rep Power

    Default looking for advice on the next step of my project

    Hi all,

    I need to write a program in Java that will read from an Oracle database and write the results to a text file in a specified location.

    I have managed to create a class that will connect to my database, read from a table and return the results to the NetBeans console.

    Java Code:
    import java.sql.*;
    class SimpleOraJava {
      public static void main(String args[]) throws SQLException {
          new oracle.jdbc.driver.OracleDriver()
        String serverName = "server";
        int port = 1521;
        String user = "niku";
        String password = "nottelling";
        String SID = "mindyourown";
        String URL = "jdbc:oracle:thin:@" + serverName + ":" + port + ":" + SID;
        Connection conn = DriverManager.getConnection(URL, user, password);
        Statement stat = conn.createStatement();
        ResultSet rs = stat.executeQuery(SQL);
        while ( {
            rs.getString(1) + "\t"
            + rs.getInt(2)

    I am very new to Java programming, so didn;t know the right way of doing things.
    I'm not sure what different classes I need.
    Do I write it all in one class (not sure when to seperare classes)

    My next stage on the above is to write the results to a text file.
    I have no idea how to do that, although I have included the* library into the above already.

    Can anybody offer some advice about creating my 'program'. How do I know what bits to put in different classes? and how do I write to the text file (I am currently looping through the restults)

    thanks in advance,

  2. #2
    xcallmejudasx's Avatar
    xcallmejudasx is offline Senior Member
    Join Date
    Oct 2008
    Houston, TX & Flint, MI
    Rep Power


    BufferedWriter and FileWriter are the classes you want. These will allow you to write your output to a text file directly.

    Also BufferedReader and FileReader will do the opposite in case you need to retrieve the information later.
    Liberty has never come from the government.
    Liberty has always come from the subjects of government.
    The history of liberty is the history of resistance.
    The history of liberty is a history of the limitation of governmental power, not the increase of it.

  3. #3
    matpj is offline Member
    Join Date
    Sep 2008
    Rep Power


    thanks for the response.
    Do I just include these in the same class and do all coding in there?
    i'm not sure of the 'right' way of coding in Java!

Similar Threads

  1. EJB3 Message driven beans step-by-step guide
    By nix123456 in forum Enterprise JavaBeans (EJB)
    Replies: 3
    Last Post: 09-28-2009, 01:29 PM
  2. whats my next step
    By thirumurugan.sethu in forum New To Java
    Replies: 4
    Last Post: 10-02-2008, 09:03 PM
  3. Advice on best method for....
    By shaungoater in forum Java 2D
    Replies: 1
    Last Post: 06-23-2008, 07:36 PM
  4. Step-by-Step Tutorial: Achieve RAD with Seam+Eclipse+Tomcat
    By Techieexchange in forum JavaServer Faces (JSF)
    Replies: 0
    Last Post: 11-13-2007, 07:13 PM
  5. Step-by-Step 0.95
    By JavaBean in forum Java Software
    Replies: 0
    Last Post: 07-14-2007, 08:17 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts