Help coderanch get a
new server
by contributing to the fundraiser
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

illegal start of expression

 
Ranch Hand
Posts: 68
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Hibernate Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
thnx guys,
I got the problem solved.
 
Tim LeMaster
Ranch Hand
Posts: 226
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Whose rules are you playing by? This tiny ad doesn't respect those rules:
We need your help - Coderanch server fundraiser
https://coderanch.com/t/782867/Coderanch-server-fundraiser
reply
    Bookmark Topic Watch Topic
  • New Topic