Getting one illegal start of expression . Please help!!

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • rajesh619
    New Member
    • Sep 2007
    • 1

    Getting one illegal start of expression . Please help!!

    I'm new to programming. I have created a servlet which retrieves values from the database after a value is put into the HTML page to which it is attached. But during compilation, it shows two errors. Please help me in solving this error.



    import java.io.*;
    import java.util.Enume ration;
    import javax.servlet.* ;
    import javax.servlet.h ttp.*;
    import java.sql.*;
    import java.net.*;
    public class search extends HttpServlet
    {
    Connection con;
    private ServletConfig config;


    public void init(ServletCon fig config) throws ServletExceptio n
    {
    this.config=con fig;
    }

    public void service (HttpServletReq uest req, HttpServletResp onse res)
    throws ServletExceptio n, IOException
    {

    HttpSession session = req.getSession( true);

    res.setContentT ype("text/html");

    PrintWriter out = res.getWriter() ;

    out.println("<H TML><HEAD><TITL E>Search Results</TITLE>");

    out.println("</HEAD>");

    out.println("<B ODY bgColor=blanche dalmond text=#008000 topMargin=0>");

    out.println("<P align=center><F ONT face=Helvetica> <FONT color=fuchsia style=\"BACKGRO UND-COLOR: white\"><BIG><B IG>List of Songs</BIG></BIG></FONT></P>");

    out.println("<P align=center>") ;

    out.println("<T ABLE align=center border=1 cellPadding=1 cellSpacing=1 width=\"75%\">" );

    out.println("<T R>");

    out.println("<T D>Category</TD>");

    out.println("<T D>Artist</TD>");

    out.println("<T D>Song</TD>");

    out.println("<T D>Movie/Album</TD>");

    out.println("<T D>Link</TD></TR>");

    try
    {


    Class.forName(" sun.jdbc.odbc.J dbcOdbcDriver") ;
    con = DriverManager.g etConnection("j dbc:odbc:MyData Source", "sa", "");
    Statement stat=con.create Statement();
    String category=req.ge tParameter("cat egory");
    String artist=req.getP arameter("artis t");
    String song=req.getPar ameter("song");
    String movie=req.getPa rameter("movie" );

    if(artist.lengt h() == 0 && category == "select a category" && song.length() == 0 && movie.length() !== 0)
    {
    ResultSet result = stat.executeQue ry("select * from music where c_movie = '" + movie + "'");
    }

    else if(artist.lengt h() !== 0 && song.length() == 0 && category == "select a category" && movie.length() !== 0)
    {
    ResultSet result=stat.exe cuteQuery("sele ct * from music where c_artist = '" + artist + "' and c_movie = '" + movie + "'");
    }

    else if(song.length( ) !== 0 && artist.length() !== 0 && category == "select a category" && movie.length() !== 0)
    {
    ResultSet result=stat.exe cuteQuery("sele ct * from music where c_movie = '" + movie + "' and c_artist = '" + artist + "' and c_song = '" + song + "'");
    }

    else if(song.length( ) == 0 && artist.length() == 0 && category !== "select a category" && movie.length() == 0)
    {
    ResultSet result=stat.exe cuteQuery("sele ct * from music where c_category = '" + category + "'");
    }

    else if(song.length( ) !== 0 && artist.length() == 0 && category !== "select a category" && movie.length() == 0)
    {
    ResultSet result=stat.exe cuteQuery("sele ct * from music where c_song = '" + song + "' and c_category = '" + category + "'");
    }

    else if(song.length( ) !== 0 && artist.length() !== 0 && category == "select a category" && movie.length() == 0)
    {
    ResultSet result=stat.exe cuteQuery("sele ct * from music where c_song = '" + song + "' and c_artist = '" + artist + "'");
    }

    else if(song.length( ) == 0 && artist.length() !== 0 && category == "select a category" && movie.length() == 0)
    {
    ResultSet result=stat.exe cuteQuery("sele ct * from music where c_artist = '" + artist + "'");
    }

    else if(song.length( ) !== 0 && artist.length() == 0 && category == "select a category" && movie.length() == 0)
    {
    ResultSet result=stat.exe cuteQuery("sele ct * from music where c_song = '" + song + "'");
    }

    else if(song.length( ) !== 0 && artist.length() == 0 && category !== "select a category" && movie.length() !== 0)
    {
    ResultSet result=stat.exe cuteQuery("sele ct * from music where c_song = '" + song + "' and c_category = '" + category + "' and c_movie = '" + movie + "'");
    }

    else if(song.length( ) == 0 && artist.length() !== 0 && category !== "select a category" && movie.length() !== 0)
    {
    ResultSet result=stat.exe cuteQuery("sele ct * from music where c_artist = '" + artist + "' and c_category = '" + category + "' and c_movie = '" + movie + "'");
    }

    else if(song.length( ) !== 0 && artist.length() !== 0 && category !== "select a category" && movie.length() == 0)
    {
    ResultSet result=stat.exe cuteQuery("sele ct * from music where c_artist = '" + artist + "' and c_category = '" + category + "' and c_song = '" + song + "'");
    }

    else if(song.length( ) !== 0 && artist.length() !== 0 && category !== "select a category" && movie.length() !== 0)
    {
    ResultSet result=stat.exe cuteQuery("sele ct * from music where c_artist = '" + artist + "' and c_category = '" + category + "' and c_movie = '" + movie + "' and c_song = '" + song + "'");
    }

    else(song.lengt h() == 0 && artist.length() == 0 && category == "select a category" && movie.length() == 0)
    {
    ResultSet result=stat.exe cuteQuery("sele ct * from music");
    }



    while(result.ne xt())
    {

    out.println();

    out.println("<T R>");

    out.println("<T D>" + result.getStrin g(1) + "</TD>");

    out.println("<T D>" + result.getStrin g(2) + "</TD>");

    out.println("<T D>" + result.getStrin g(3) + "</TD>");

    out.println("<T D>" + result.getStrin g(4) + "</TD>");

    out.println("<T D><a href = 'http://www.abczxyz.com '>Download</a></TD>");

    out.println("</TR>");
    }
    result.close();

    stat.close();

    con.close();

    }
    catch(Exception e)
    {

    out.println(e.g etMessage());

    }

    out.println("</TABLE></P>");

    out.println("<P >&nbsp;</P></FONT></BODY></HTML>");

    }
    }


    The error is:
    search.java:64: illegal start of expression
    if(artist.lengt h() == 0 && category == "select a category" && song.length() =
    = 0 && movie.length() !== 0)

    ^
    search.java:150 : ')' expected
    result.close();
    ^
  • r035198x
    MVP
    • Sep 2006
    • 13225

    #2
    1.) Use code tags when posting code
    2.) Indent your code. It makes it easier for people (including yourself) to read that code.
    3.) When comparing strings, use the .equals method as in
    [CODE=java]if (name.equals("r 035198x")) {
    //....
    }
    [/CODE]

    4.) Use brackets () to tell the compiler what you mean as in
    don't say
    Code:
    if(true | false & true)
    but say
    [CODE=java]if((true | false) & true)[/CODE]

    Comment

    • JosAH
      Recognized Expert MVP
      • Mar 2007
      • 11453

      #3
      Originally posted by rajesh619
      movie.length() !== 0)
      !== is nog an operator hence the compiler diagnostic; there's a whole lot more
      wrong with this code but first try to get it through the compiler.

      kind regards,

      Jos

      Comment

      • r035198x
        MVP
        • Sep 2006
        • 13225

        #4
        Originally posted by JosAH
        !== is nog an operator hence the compiler diagnostic; there's a whole lot more
        wrong with this code but first try to get it through the compiler.

        kind regards,

        Jos
        However you managed to spot that ...

        Comment

        • JosAH
          Recognized Expert MVP
          • Mar 2007
          • 11453

          #5
          Originally posted by r035198x
          However you managed to spot that ...
          I don't have an avatar so I have good eyesight ;-)

          kind regards,

          Jos

          Comment

          Working...