954,518 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

JDBC problem

HI

I m using excel as a database..

In my DB i m having fields name and some value assigned to each name..

Now on my jsp page i m generating an array of names by some processing..

Now what i want is to access the names from the DB which r nor present in the array that i've generated. Want to get names and values other than array names..

how can i do this..

plz reply.

thanks

abhi287
Light Poster
28 posts since Dec 2007
Reputation Points: 10
Solved Threads: 0
 

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
Moderator
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
Moderator
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
Team Colleague
8,392 posts since Nov 2004
Reputation Points: 1,662
Solved Threads: 337
 

If your question is about accessing the excel as your DB, then:

Microsoft provides a driver for that, and you can use JDBC to access your excel (DB) like any other database. you need to create a data source for your excel (DB).

new_2_java
Junior Poster
127 posts since Apr 2007
Reputation Points: 7
Solved Threads: 6
 

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
Team Colleague
8,392 posts since Nov 2004
Reputation Points: 1,662
Solved Threads: 337
 

Hi all

thanks for all reply..

i just want to know how to compare a field in a database with the array..

means suppose i've array of names and i want to access those names from the database other than the array that i've.

i m using--

for(int i=0;i<my_arr.length;i++)
{
query = "select * from my_table where HR=(select max(HR) from my_table where FirstName <>'"+my_arr[l]+	"' )";
}


here actually i want to compare FirstName with total my_arr..
Means get HR whose FirstName is not equals to all names in my_arr.
As per i m using it'll compare only one name at a time,but i want to compare with array..

how it is possible??

plz reply..
thanks..

abhi287
Light Poster
28 posts since Dec 2007
Reputation Points: 10
Solved Threads: 0
 

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
Moderator
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+")";

}
sirishag.ch
Newbie Poster
4 posts since Mar 2008
Reputation Points: 10
Solved Threads: 0
 

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
Team Colleague
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
Team Colleague
3,329 posts since Dec 2007
Reputation Points: 1,014
Solved Threads: 448
 

yeah U r correct i have given the basic idea .As ,I'm in a hurry i forgot to remove the second loop.

sirishag.ch
Newbie Poster
4 posts since Mar 2008
Reputation Points: 10
Solved Threads: 0
 

Ok then, sorry about my comments concerning the second loop.

javaAddict
Nearly a Senior Poster
Team Colleague
3,329 posts since Dec 2007
Reputation Points: 1,014
Solved Threads: 448
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You