Results 1 to 4 of 4
- 01-28-2009, 06:15 PM #1
Member
- Join Date
- Sep 2008
- Posts
- 42
- Rep Power
- 0
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 (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 {
Java 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
-
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!
- 01-28-2009, 08:30 PM #3
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...
- 01-29-2009, 10:20 AM #4
Member
- Join Date
- Sep 2008
- Posts
- 42
- Rep Power
- 0
Similar Threads
-
java.sql.sql exceptin: io exception got minus one from a read call
By illusion1912 in forum JDBCReplies: 3Last Post: 02-17-2009, 11:11 AM -
How do i call display.setcurrent
By arnab321 in forum CLDC and MIDPReplies: 7Last Post: 11-04-2008, 09:00 PM -
cannot call private method from static method
By jon80 in forum New To JavaReplies: 3Last Post: 05-07-2008, 08:37 AM -
Read-File Write Display substring
By hiklior in forum New To JavaReplies: 3Last Post: 04-18-2008, 11:45 AM -
Simplest way to read and display a jpeg image
By Hasan in forum New To JavaReplies: 1Last Post: 05-31-2007, 03:42 PM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks