473,738 Members | 6,332 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Getting one illegal start of expression . Please help!!

1 New Member
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();
^
Sep 12 '07 #1
4 3079
r035198x
13,262 MVP
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
Expand|Select|Wrap|Line Numbers
  1. if (name.equals("r035198x")) {
  2. //....
  3. }
  4.  
4.) Use brackets () to tell the compiler what you mean as in
don't say
Expand|Select|Wrap|Line Numbers
  1. if(true | false & true)
but say
Expand|Select|Wrap|Line Numbers
  1. if((true | false) & true)
Sep 12 '07 #2
JosAH
11,448 Recognized Expert MVP
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
Sep 12 '07 #3
r035198x
13,262 MVP
!== 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 ...
Sep 12 '07 #4
JosAH
11,448 Recognized Expert MVP
However you managed to spot that ...
I don't have an avatar so I have good eyesight ;-)

kind regards,

Jos
Sep 12 '07 #5

Sign in to post your reply or Sign up for a free account.

Similar topics

1
1981
by: worzel | last post by:
Hi All, I am looking for a reg ex that will match email addresses withing <a href=mailto blah > links. Actually, I already crafted my own, but with a slight problem: <a href="mailto:fred@blah.com"> emal me</a> woud be matched as expected, but so will:
1
1670
by: Christina Feichter | last post by:
Hello All How can i start a help-file like help.chm? Thanks
9
1792
by: Schorschi | last post by:
Not having used regular expressions much, I need some help. Given a string... "This\0Guy\0Needs\0Some\0Help\0\0\0\0\0" Need result as array of strings... "This","Guy", "Needs", "Some", "Help" Where '\0' is a literal zero-byte. I think I need two regular expressions? One to strip the multiple instances of '\0' bytes, and another to split the string.
2
1726
by: ankit | last post by:
I want to get the start and end of all the patterns mattched in regex. I know I can get it with start() and end() fn of matched objects. But re.search() return the match object of first matching regex in the string. I want all match objects in that string Here is the string : tmplstr = """ ${name}
2
6629
by: dobbouk | last post by:
I'm getting these 2 errors and haven't got a clue whats causing them please java 43: illegal start of type for (i=0;i< Number_of_squares; i++) java 215 identifier expected } heres the whole code
1
2532
by: biznitchil | last post by:
it is a bit jacked up, but copy and paste it into an IDE(i use jGRASP) plz help me...it worked just fine before I added the menu..you can e-mail me if you have any <Removed> import java.util.*; public class VowelsConsCounter { public int i= list.indexOf(object); public static char getMenuSelection(); { String input; char selection; Scanner keyboard = new Scanner(System.in);
2
4627
by: mole40 | last post by:
Hello! I'm very new to writing java. And I keep getting the "Illegal Start of Type" error. I've tried everything to fix it. can anyone help me? import java.util.*; class ClockTalk { public static void main(String arguments) { //get current time and date Calenda now = Calendar.getInstance(); int hour = now.get(Calendr.HOUR_OF_DAY); int minute = now.get(Calendar.MINUTE);
1
3114
by: John Luttig | last post by:
import java.awt.*; import java.awt.event.* ; import java.awt.image.*; import java.awt.geom.* ; import javax.swing.* ; import javax.swing.event.* ; public class NPCObject { public void NPCObject(int strength, int defense, boolean attackable, String imageFile, int x, int y) {
2
22362
by: Christina Arena | last post by:
I'm just starting to learn java as part of a class I am required to take as a math major. I am feeling completely lost. I guess we're supposed to learn this as independently as possible. I was watching a video and tried copying the author's code into bluej and it gives me an error. I apologize in advance if I am not copying it here correctly. class WhileLoop { int counter=0; while (counter<10) { System.out.println...
0
8968
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9334
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
9259
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9208
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8208
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6750
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6053
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
1
3279
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
2744
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.