int counter;
counter=1;
rs = statement.executeQuery("SELECT * FROM Quiz WHERE SrNo=counterr");

("SELECT * FROM Quiz WHERE SrNo=counterr") You can't force an undefined variable into the query (typo?). Also, the query will not understand that the counter is a variable but rather expects it to be an internal keyword in SQL. What you may want is ("SELECT * FROM Quiz WHERE SrNo="+counter)...

is 'counterr' in your last statement supposed to be the int counter defined above it? If so...

rs = statement.executeQuery("SELECT * FROM Quiz WHERE SrNo = " + counter + ";");

THanks a lot guys. It worked. This problem is solved I'm very thankful to you.

BUt I've a question how can I print only 3 top score order wise. I mean if 100,99,98 are top scores only they should be displayed the remaining should be skipped. How can I do that?THanks once again.

Try using TOP 'N' in your select statement...

SELECT TOP 3 * ... ORDER BY {scoreColumnName} DESC

This works with MSSQLServer. It may be different depending on the DB Server you are running.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.