• Post Reply Bookmark Topic Watch Topic
  • New Topic

illegal start of expression  RSS feed

 
Ranch Hand
Posts: 68
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi,
I have an illegal start of expression exception at function retnAL()
Can some body help me solving the exception


import java.io.*;
import java.net.*;
import java.sql.*;
import java.util.*;

public class xlsRead{
public static final String DRIVER_NAME =
"sun.jdbc.odbc.JdbcOdbcDriver";
public static final String DATABASE_URL = "jdbc dbc:exl";

public static void main(String[] args)
throws ClassNotFoundException, SQLException{
Class.forName(DRIVER_NAME);
Connection con = null;
try {
con = DriverManager.getConnection(DATABASE_URL);
//Connection conn = DriverManager.getConnection("jdbc dbc rcl","SMARISETTY","SMARISETTY" );
Statement stmt = con.createStatement();
//Statement statement = conn.createStatement
ResultSet rs = stmt.executeQuery
("select NAME from [bball$]");
ArrayList al = new ArrayList();

while (rs.next()) {
String lname = rs.getString(1);
al.add(lname);
//String fname = rs.getString(2);
//int id = rs.getInt(3);

//System.out.println(lname);
}

public ArrayList retnAL()
{
return (al);
}
rs.close();
stmt.close();
}
finally {
if (con != null)
con.close();
}
}
}
 
Sam Venkata
Ranch Hand
Posts: 68
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
thnx Paul I changed it to
return al ;
but still I have the same problem, I think it is the problem with the method declaration.
could you or somebody please help me.

thnx,
Samanth.
 
Bartender
Posts: 10336
Eclipse IDE Hibernate Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It looks like you are trying to define a method inside your main method. That's not something you can do.
 
Ranch Hand
Posts: 226
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You can't just put a method in the middle of another method. Your code is basically this



What are you trying to accomplish?
 
Sam Venkata
Ranch Hand
Posts: 68
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I wanted to access the arraylist in another java class so I was trying to write a method so that I could call it from that class.
Could you please explain me how to do it?

thnx,
Samanth.
 
Sam Venkata
Ranch Hand
Posts: 68
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
thnx guys,
I got the problem solved.
 
Tim LeMaster
Ranch Hand
Posts: 226
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Well instead of making the public static void main(String[] argv) make it just another method that another class can call and return the ArrayList.



I wouldn't call this finished or perfect code but it should get you started. I didn't check it for typos in a compiler.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!