How can I call my database read method to display its ArrayList?
Hi there,
I have created a class/method which performs a database read and fills an ArrayList.
Code:
public class EntityProvider {
public void readEntities() throws SQLException, IOException {
ArrayList <String> fileArray = new ArrayList<String>();
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 DISTINCT level2_name " +
"FROM niku.nbi_dim_obs " +
"WHERE level1_name = 'DSTi Global' " +
"AND level2_name is not null";
String newLine = System.getProperty("line.separator");
Statement stat = conn.createStatement();
ResultSet rs = stat.executeQuery(SQL);
while (rs.next()) { //cycle through result set
fileArray.add(rs.getString(1));
}
for(String name : fileArray){
System.out.println(name);
}
stat.close();
conn.close();
}
}
In a second class I am trying to call this method to display its list, but I am getting an error:
Void Type not allowed here
public class ShowEntities {
Code:
public static void main(String args[]){
EntityProvider entityCombo = new EntityProvider();
System.out.println(entityCombo.readEntities());
}
}
please can somebody advise?
i'm a little lost with Java at the moment.
thanks in advance,
Matt