Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 01-14-2009, 05:37 PM
Member
 
Join Date: Sep 2008
Posts: 42
Rep Power: 0
matpj is on a distinguished road
Default How to construct my finished program?
Hi all,

I have asked a few questions on here recently, seeking answers to complete a task where I read from a database and then write the results, as fixed length values, to a text file.

I have successfully acheived this on a test scale, thanks to all your help.

However,
What I need to deliver is a small GUI that the user will use to choose which of the 3 QUERIES to run (to date I have generated a program that uses one of the Queries)

Each one will have a different select statement with a different number/format of fields.
Each of them will need to write to a text file (with a different file name)

My questions are as follows:
  • I have one datasource that all 3 will need to connect to.
    How would I specify it once to avoid needless duplication?
  • How would I construct it so that I have a simple JFrame where the user chooses which program to run?

here is what I have for one of the programs:
Code:
import java.sql.*;
import java.io.*;
import java.io.FileWriter;


class PSResData {

    public static String padRight(String s, int n) {
        return String.format("%1$-" + n + "s", s).substring(0, n);


    }

    public static String padLeft(String s, int n) {
        // Method to pad out the database fields
        // Call for each field with the specified length
        return String.format("%1$#" + n + "s", s);
    }

    public static void main(String args[]) throws SQLException, IOException {

        DriverManager.registerDriver(new oracle.jdbc.driver.OracleDriver());
        int count = 0;
        
        String serverName = "francisca";
        int port = 1521;
        String user = "niku";
        String password = "niku";
        String SID = "nikuuat";
        String URL = "jdbc:oracle:thin:@" + serverName + ":" + port + ":" + SID;

        Connection conn = DriverManager.getConnection(URL, user, password);
        String SQL = "SELECT '25000', DECODE(IS_ACTIVE, 1, 'A', 'I'), UNIQUE_NAME, " +
" FIRST_NAME||LAST_NAME FROM NIKU.SRM_RESOURCES ";

        String newLine = System.getProperty("line.separator");


        Statement stat = conn.createStatement();
        ResultSet rs = stat.executeQuery(SQL);
        FileWriter fout = new FileWriter("c:\\test.txt"); //Create new file stream
        
        while (rs.next()) { //cycle through result set
             count++;
             String counter = ""+count;             

             fout.write(
                      padRight(rs.getString(1), 5) +
                      padRight(rs.getString(2), 1) +
                      padRight(rs.getString(3), 11) +
                      padRight(rs.getString(4), 60) + newLine
                      );
        }

        fout.close();  //close file stream
        System.out.println("Complete");
        stat.close();
        conn.close();

  }


}
Thank you all again for your assistance,
Matt
Bookmark Post in Technorati
Reply With Quote
Reply

Bookmarks

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
finished paint! diggitydoggz New To Java 3 01-04-2009 10:33 AM
How to run a code when a download is finished aneesahamedaa New To Java 4 10-14-2008 12:37 PM
[SOLVED] Construct parents using tree path. Melki AWT / Swing 2 09-23-2008 04:54 PM
How to construct checkbox in rtf document using iText? soumyanil Advanced Java 0 07-28-2008 11:05 AM
hi there i am stuck with a construct can anyone help??? sonal New To Java 3 12-05-2007 02:22 AM


All times are GMT +2. The time now is 03:03 AM.



VBulletin, Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO ©2009, Crawlability, Inc.
Copyright ©2006 - 2007, www.java-forums.org