It might help if you showed your code (and hopefully the DB stuff is in a bean and is not a scriptlet in your jsp), and then trying to better explain what it is you want, because I'm not at all sure of what it is you're asking here.
Also, use code tags when you post your code.
masijade
Industrious Poster
4,253 posts since Feb 2006
Reputation Points: 1,471
Solved Threads: 494
HI
I m using excel as a database...
Bad idea. Use a real database if you need a database.
Ezzaral
Posting Genius
15,986 posts since May 2007
Reputation Points: 3,250
Solved Threads: 847
Excel is no database.
Using JDBC to access Excel is BAD.
Using JDBC from JSP is BAD.
So it seems like you'd best completely scrap whatever you have already and start from scratch with some research into proper application architecture.
jwenting
duckman
8,392 posts since Nov 2004
Reputation Points: 1,662
Solved Threads: 337
NO, you do NOT use Excel as a database.
That's already been established firmly.
Excel is NOT a database.
Just because you can create ODBC DSNs to Excel files doesn't mean you should use those DSNs as database aliasses.
jwenting
duckman
8,392 posts since Nov 2004
Reputation Points: 1,662
Solved Threads: 337
First, as the others have said, Excel is not a DB, and you shouldn't be using it as such.
Second of all, this is an SQL question, not a Java/JSP/JDBC question. Next time, find an SQL forum.
.... where HR IN ( ....
not
.... where HR = ( ....
Edit: This should, at least, be a valid SQL now. Whether it gives you what you want is another question.
masijade
Industrious Poster
4,253 posts since Feb 2006
Reputation Points: 1,471
Solved Threads: 494
Hi ABhi,
Try Like this...
String hrname="(";
for(int k=0;k<my_arr.length;k++)
{
hrname+="'"+my_arr[k]+"',";
}
hrname+=")";
for(int i=0;i<my_arr.length;i++)
{
query = "select * from my_table where HR=(select max(HR) from my_table where FirstName not in "+hrname+")";
}
Sorry to break this to you but what you wrote is totally wrong and you are going to do serius damage to the kid who asked for help:
To start with:the first for-loop will end with the command: hrname+="'"+my_arr[k]+"',";
Meaning that after the loop the command: hrname+=")"; will generate this String:
hrname = " ...... ',) " . As you can see the comma before the parenthesis will generate an sql error.
The second for-loop is completely unnecessary. You don't use the index i, and you simply assign to the variable query the same String over and over again.
I think that you don't need the loop and only the assignment:
String query = "select * from my_table where HR=(select max(HR) from my_table where FirstName not in "+hrname+")";
javaAddict
Nearly a Senior Poster
3,329 posts since Dec 2007
Reputation Points: 1,014
Solved Threads: 448
I didn't have time to post the solution in my previous post, so here it is:
String hrname="(";
for(int k=0;k< my_arr.length-1 ;k++)
{
hrname+="'"+my_arr[k]+"',";
}
if (my_arr.length!=0) {
hrname+="'"+my_arr[my_arr.length-1]+"'";
}
hrname+=")";
javaAddict
Nearly a Senior Poster
3,329 posts since Dec 2007
Reputation Points: 1,014
Solved Threads: 448
Ok then, sorry about my comments concerning the second loop.
javaAddict
Nearly a Senior Poster
3,329 posts since Dec 2007
Reputation Points: 1,014
Solved Threads: 448