Results 1 to 3 of 3
- 12-18-2008, 03:36 PM #1
Member
- Join Date
- Sep 2008
- Posts
- 42
- Rep Power
- 0
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.*; import java.io.*; class SimpleOraJava { public static void main(String args[]) throws SQLException { DriverManager.registerDriver( 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); String SQL = "SELECT DSTI_PROJ_REF, id FROM NIKU.ODF_CA_PROJECT"; Statement stat = conn.createStatement(); ResultSet rs = stat.executeQuery(SQL); while (rs.next()) { System.out.println( rs.getString(1) + "\t" + rs.getInt(2) ); } stat.close(); conn.close(); } }
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 java.io.* 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,
Matt
- 12-18-2008, 06:01 PM #2
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.
- 12-19-2008, 03:03 PM #3
Member
- Join Date
- Sep 2008
- Posts
- 42
- Rep Power
- 0
Similar Threads
-
EJB3 Message driven beans step-by-step guide
By nix123456 in forum Enterprise JavaBeans (EJB)Replies: 3Last Post: 09-28-2009, 01:29 PM -
whats my next step
By thirumurugan.sethu in forum New To JavaReplies: 4Last Post: 10-02-2008, 09:03 PM -
Advice on best method for....
By shaungoater in forum Java 2DReplies: 1Last Post: 06-23-2008, 07:36 PM -
Step-by-Step Tutorial: Achieve RAD with Seam+Eclipse+Tomcat
By Techieexchange in forum JavaServer Faces (JSF)Replies: 0Last Post: 11-13-2007, 07:13 PM -
Step-by-Step 0.95
By JavaBean in forum Java SoftwareReplies: 0Last Post: 07-14-2007, 08:17 PM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks