Forum Stats

  • 3,854,659 Users
  • 2,264,395 Discussions
  • 7,905,748 Comments

Discussions

looking for a method that reads in a whole row for data rather than using getString();

966239
966239 Member Posts: 27
edited Feb 20, 2015 7:14PM in New To Java

Hi,

  I'm using java to read from oracle and Netezza and I'm wondering:

Is there a method for capturing a row in a variable in order to print that entire row out to a data file or a UNIX file in this case.

Right now I have this code I'm working with:

  //STEP 4: Execute a query
  System.out.println("Creating statement...");
  stmt = connection.createStatement();
  String sql;
  sql = "SELECT SRC_ID, SRC_CD, SRC_DSC, CKA_SUB_ID FROM SRC"; 
  ResultSet rs = stmt.executeQuery(sql);

  //STEP 5: Extract data from result set
  while(rs.next()){
//Retrieve by column name
String SRC_ID  = rs.getString("SRC_ID");
String FIRST_ROW  = SRC_ID+", "+SRC_CD+", "+SRC_DSC+", "+CKA_SUB_ID;

//Display values
System.out.print("SRC_ID: " + SRC_ID);
System.out.println(", FIRST_ROW: " + FIRST_ROW);
                     }

Is there a way I can replace the getString with a "getRow"?

Right now the best I can do is to create and use the FIRST_ROW variable. However I want to be able to do this generically so I can read different tables and write them to data files.

Thanks!

Answers

This discussion has been closed.