Results 1 to 1 of 1
- 01-14-2009, 05:37 PM #1
Member
- Join Date
- Sep 2008
- Posts
- 42
- Rep Power
- 0
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:
Thank you all again for your assistance,Java 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(); } }
Matt
Similar Threads
-
finished paint!
By diggitydoggz in forum New To JavaReplies: 3Last Post: 01-04-2009, 10:33 AM -
How to run a code when a download is finished
By aneesahamedaa in forum New To JavaReplies: 4Last Post: 10-14-2008, 12:37 PM -
[SOLVED] Construct parents using tree path.
By Melki in forum AWT / SwingReplies: 2Last Post: 09-23-2008, 04:54 PM -
How to construct checkbox in rtf document using iText?
By soumyanil in forum Advanced JavaReplies: 0Last Post: 07-28-2008, 11:05 AM -
hi there i am stuck with a construct can anyone help???
By sonal in forum New To JavaReplies: 3Last Post: 12-05-2007, 02:22 AM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks