Results 1 to 4 of 4
  1. #1
    matpj is offline Member
    Join Date
    Sep 2008
    Rep Power

    Default 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.

    Java 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 ( { //cycle through result set
            for(String name : fileArray){

    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 {

    Java Code:
        public static void main(String args[]){
            EntityProvider entityCombo = new EntityProvider();

    please can somebody advise?
    i'm a little lost with Java at the moment.
    thanks in advance,

  2. #2
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Blog Entries
    Rep Power


    perhaps you want to make the readEntities return an ArrayList and not return void as currently written. Then you could just return the fileArray from the method when it's through.

    Also, this class appears to be something like a utility class that only holds helper methods. I think (correct me if I'm wrong anybody), that this may be an OK place to use static methods.

    Best of luck!

  3. #3
    Steve11235's Avatar
    Steve11235 is offline Senior Member
    Join Date
    Dec 2008
    Rep Power


    Fubarable is right.

    Your exception is caused by the fact that readEntities() returns void; println() can't do anything with a void return.

    You are already printing the name in the first class. Just get rid of the println() in the second.

    As Fubarable pointed out, your first class isn't of much value unless it returns something...

  4. #4
    matpj is offline Member
    Join Date
    Sep 2008
    Rep Power


    thanks guys.
    I removed the println and also had to throw the SQLException in the main method (as well as importing the SQL libraries)
    Is it right that I need to import java.sql.* in the class that calls another class containing SQL code?

Similar Threads

  1. Replies: 3
    Last Post: 02-17-2009, 11:11 AM
  2. How do i call display.setcurrent
    By arnab321 in forum CLDC and MIDP
    Replies: 7
    Last Post: 11-04-2008, 09:00 PM
  3. cannot call private method from static method
    By jon80 in forum New To Java
    Replies: 3
    Last Post: 05-07-2008, 08:37 AM
  4. Read-File Write Display substring
    By hiklior in forum New To Java
    Replies: 3
    Last Post: 04-18-2008, 11:45 AM
  5. Simplest way to read and display a jpeg image
    By Hasan in forum New To Java
    Replies: 1
    Last Post: 05-31-2007, 03:42 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts