943,960 Members | Top Members by Rank

Ad:
  • Java Discussion Thread
  • Unsolved
  • Views: 1419
  • Java RSS
You are currently viewing page 1 of this multi-page discussion thread
Mar 20th, 2008
0

JDBC problem

Expand Post »
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
Similar Threads
Reputation Points: 10
Solved Threads: 0
Light Poster
abhi287 is offline Offline
28 posts
since Dec 2007
Mar 20th, 2008
0

Re: JDBC problem

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.
Moderator
Reputation Points: 1471
Solved Threads: 490
Industrious Poster
masijade is offline Offline
4,043 posts
since Feb 2006
Mar 20th, 2008
0

Re: JDBC problem

Click to Expand / Collapse  Quote originally posted by abhi287 ...
HI

I m using excel as a database...
Bad idea. Use a real database if you need a database.
Moderator
Featured Poster
Reputation Points: 3239
Solved Threads: 839
Posting Genius
Ezzaral is offline Offline
6,761 posts
since May 2007
Mar 20th, 2008
0

Re: JDBC problem

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.
Team Colleague
Reputation Points: 1658
Solved Threads: 331
duckman
jwenting is offline Offline
7,719 posts
since Nov 2004
Mar 20th, 2008
-1

Re: JDBC problem

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).
Reputation Points: 7
Solved Threads: 6
Junior Poster
new_2_java is offline Offline
127 posts
since Apr 2007
Mar 20th, 2008
0

Re: JDBC problem

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.
Team Colleague
Reputation Points: 1658
Solved Threads: 331
duckman
jwenting is offline Offline
7,719 posts
since Nov 2004
Mar 21st, 2008
0

Re: JDBC problem

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--
Java Syntax (Toggle Plain Text)
  1. for(int i=0;i<my_arr.length;i++)
  2. {
  3. query = "select * from my_table where HR=(select max(HR) from my_table where FirstName <>'"+my_arr[l]+ "' )";
  4. }

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..
Reputation Points: 10
Solved Threads: 0
Light Poster
abhi287 is offline Offline
28 posts
since Dec 2007
Mar 21st, 2008
0

Re: JDBC problem

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.

Java Syntax (Toggle Plain Text)
  1. .... where HR IN ( ....
not
Java Syntax (Toggle Plain Text)
  1. .... where HR = ( ....

Edit: This should, at least, be a valid SQL now. Whether it gives you what you want is another question.
Last edited by masijade; Mar 21st, 2008 at 2:10 pm.
Moderator
Reputation Points: 1471
Solved Threads: 490
Industrious Poster
masijade is offline Offline
4,043 posts
since Feb 2006
Mar 22nd, 2008
0

Re: JDBC problem

Hi ABhi,
Try Like this...

java Syntax (Toggle Plain Text)
  1. String hrname="(";
  2. for(int k=0;k<my_arr.length;k++)
  3. {
  4.  
  5. hrname+="'"+my_arr[k]+"',";
  6. }
  7. hrname+=")";
  8.  
  9. for(int i=0;i<my_arr.length;i++)
  10. {
  11. query = "select * from my_table where HR=(select max(HR) from my_table where FirstName not in "+hrname+")";
  12.  
  13. }
Last edited by WolfPack; Mar 22nd, 2008 at 2:49 am. Reason: Added code tags. Use them the next time you post code.
Reputation Points: 10
Solved Threads: 0
Newbie Poster
sirishag.ch is offline Offline
4 posts
since Mar 2008
Mar 22nd, 2008
0

Re: JDBC problem

Hi ABhi,
Try Like this...

java Syntax (Toggle Plain Text)
  1. String hrname="(";
  2. for(int k=0;k<my_arr.length;k++)
  3. {
  4.  
  5. hrname+="'"+my_arr[k]+"',";
  6. }
  7. hrname+=")";
  8.  
  9. for(int i=0;i<my_arr.length;i++)
  10. {
  11. query = "select * from my_table where HR=(select max(HR) from my_table where FirstName not in "+hrname+")";
  12.  
  13. }
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:
Java Syntax (Toggle Plain Text)
  1. String query = "select * from my_table where HR=(select max(HR) from my_table where FirstName not in "+hrname+")";
Last edited by javaAddict; Mar 22nd, 2008 at 7:52 am.
Sponsor
Featured Poster
Reputation Points: 1014
Solved Threads: 446
Nearly a Senior Poster
javaAddict is offline Offline
3,259 posts
since Dec 2007

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in Java Forum Timeline: Absolute value of a "double" variable?
Next Thread in Java Forum Timeline: question about compiling





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC