Win a copy of Rust Web Development this week in the Other Languages forum!
  • 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:
  • Tim Cooke
  • Campbell Ritchie
  • Ron McLeod
  • Liutauras Vilda
  • Jeanne Boyarsky
Sheriffs:
  • Junilu Lacar
  • Rob Spoor
  • Paul Clapham
Saloon Keepers:
  • Tim Holloway
  • Tim Moores
  • Jesse Silverman
  • Stephan van Hulst
  • Carey Brown
Bartenders:
  • Al Hobbs
  • Piet Souris
  • Frits Walraven

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.
 
WHAT is your favorite color? Blue, no yellow, ahhhhhhh! Tiny ad:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
reply
    Bookmark Topic Watch Topic
  • New Topic