JDBC problem

Please support our Java advertiser: Programming Forums - DaniWeb Sister Site
Reply

Join Date: Dec 2007
Posts: 28
Reputation: abhi287 is an unknown quantity at this point 
Solved Threads: 0
abhi287 abhi287 is offline Offline
Light Poster

JDBC problem

 
0
  #1
Mar 20th, 2008
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
Reply With Quote Quick reply to this message  
Join Date: Feb 2006
Posts: 2,450
Reputation: masijade has much to be proud of masijade has much to be proud of masijade has much to be proud of masijade has much to be proud of masijade has much to be proud of masijade has much to be proud of masijade has much to be proud of masijade has much to be proud of masijade has much to be proud of 
Solved Threads: 261
Moderator
masijade's Avatar
masijade masijade is offline Offline
Nearly a Posting Maven

Re: JDBC problem

 
0
  #2
Mar 20th, 2008
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.
Java Programmer and Sun Systems Administrator

----------------------------------------------

Debugging is twice as hard as writing the code in the first place. Therefore, if you write the code as cleverly as possible, you are, by definition, not smart enough to debug it.
--Brian Kernighan
Reply With Quote Quick reply to this message  
Join Date: May 2007
Posts: 4,500
Reputation: Ezzaral has much to be proud of Ezzaral has much to be proud of Ezzaral has much to be proud of Ezzaral has much to be proud of Ezzaral has much to be proud of Ezzaral has much to be proud of Ezzaral has much to be proud of Ezzaral has much to be proud of Ezzaral has much to be proud of Ezzaral has much to be proud of 
Solved Threads: 521
Moderator
Featured Poster
Ezzaral's Avatar
Ezzaral Ezzaral is offline Offline
Industrious Poster

Re: JDBC problem

 
0
  #3
Mar 20th, 2008
Originally Posted by abhi287 View Post
HI

I m using excel as a database...
Bad idea. Use a real database if you need a database.
Reply With Quote Quick reply to this message  
Join Date: Nov 2004
Posts: 6,143
Reputation: jwenting is just really nice jwenting is just really nice jwenting is just really nice jwenting is just really nice 
Solved Threads: 213
Team Colleague
jwenting's Avatar
jwenting jwenting is offline Offline
duckman

Re: JDBC problem

 
0
  #4
Mar 20th, 2008
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.
As people are clearly allowed to attack me but I'm not allowed to defend myself, I no longer post to this site.
Reply With Quote Quick reply to this message  
Join Date: Apr 2007
Posts: 126
Reputation: new_2_java is an unknown quantity at this point 
Solved Threads: 6
new_2_java new_2_java is offline Offline
Junior Poster

Re: JDBC problem

 
-1
  #5
Mar 20th, 2008
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).
Reply With Quote Quick reply to this message  
Join Date: Nov 2004
Posts: 6,143
Reputation: jwenting is just really nice jwenting is just really nice jwenting is just really nice jwenting is just really nice 
Solved Threads: 213
Team Colleague
jwenting's Avatar
jwenting jwenting is offline Offline
duckman

Re: JDBC problem

 
0
  #6
Mar 20th, 2008
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.
As people are clearly allowed to attack me but I'm not allowed to defend myself, I no longer post to this site.
Reply With Quote Quick reply to this message  
Join Date: Dec 2007
Posts: 28
Reputation: abhi287 is an unknown quantity at this point 
Solved Threads: 0
abhi287 abhi287 is offline Offline
Light Poster

Re: JDBC problem

 
0
  #7
Mar 21st, 2008
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--
  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..
Reply With Quote Quick reply to this message  
Join Date: Feb 2006
Posts: 2,450
Reputation: masijade has much to be proud of masijade has much to be proud of masijade has much to be proud of masijade has much to be proud of masijade has much to be proud of masijade has much to be proud of masijade has much to be proud of masijade has much to be proud of masijade has much to be proud of 
Solved Threads: 261
Moderator
masijade's Avatar
masijade masijade is offline Offline
Nearly a Posting Maven

Re: JDBC problem

 
0
  #8
Mar 21st, 2008
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.

  1. .... where HR IN ( ....
not
  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.
Java Programmer and Sun Systems Administrator

----------------------------------------------

Debugging is twice as hard as writing the code in the first place. Therefore, if you write the code as cleverly as possible, you are, by definition, not smart enough to debug it.
--Brian Kernighan
Reply With Quote Quick reply to this message  
Join Date: Mar 2008
Posts: 4
Reputation: sirishag.ch is an unknown quantity at this point 
Solved Threads: 0
sirishag.ch sirishag.ch is offline Offline
Newbie Poster

Re: JDBC problem

 
0
  #9
Mar 22nd, 2008
Hi ABhi,
Try Like this...

  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.
Reply With Quote Quick reply to this message  
Join Date: Dec 2007
Posts: 1,700
Reputation: javaAddict is a name known to all javaAddict is a name known to all javaAddict is a name known to all javaAddict is a name known to all javaAddict is a name known to all javaAddict is a name known to all 
Solved Threads: 227
Featured Poster
javaAddict's Avatar
javaAddict javaAddict is offline Offline
Posting Virtuoso

Re: JDBC problem

 
0
  #10
Mar 22nd, 2008
Originally Posted by sirishag.ch View Post
Hi ABhi,
Try Like this...

  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:
  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.
Check out my New Bike at my Public Profile at the "About Me" tab
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



Tag cloud for Java
About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC