Win a copy of Learn Spring Security (video course) this week in the Spring forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

JDBC doesn't retrieve all the results available in the MSSQL database

 
Alexander Selling
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hey guys!

I really have no clue what's going on at all.. I've noticed lately how sometimes I won't get as many results from a query in Java as I get from doing the exact same SQL query from within the MSSQL Server Management Studio.
I've tried to include the MSSQL manager output and the java output, with the output data omitted. And my class that connects to the database is also pasted in there.
Basically the same query retrieves 26 results from within the MSSQL manager and only 16 from java ?!
Please point me in the right direction here

Thanks in advance !

Edited to remove screenshot: please post text.
 
Tom Reilly
Rancher
Posts: 618
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Before you edited your post, you had two different select statements. One had "where key=XXXX" and the other had "where key=YYYY"
 
Misha Ver
Ranch Hand
Posts: 470
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I would suggest to post code by using code tags, instead of screen shots.
 
David Newton
Author
Rancher
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm removing the screenshot. Please post text.
 
Alexander Selling
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Tom Reilly wrote:Before you edited your post, you had two different select statements. One had "where key=XXXX" and the other had "where key=YYYY"


Yeah I noticed that, I just took the picture earlier and happened to paste that one, it is the exact same query though.
I just took the screenshots cause I thought it would make things clearer, seeing how the MSSQL manager gets more results even though the sql syntax is exactly the same.

 
David Newton
Author
Rancher
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Now the SQL and JDBC query results...
 
Alexander Selling
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I don't really know how to describe the output, I'm getting 26 rows of results from the MSSQL manager and only 16 rows from java, I guess I was more asking if you guys had ever experienced anything like it ?
Since it is a very simple query merely a select statement, how could there be a difference ?
I'll give you some more (smaller) screenshots if you'd like ?
 
David Newton
Author
Rancher
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
No, I think we've been pretty clear that we want text--this shouldn't be difficult. No, I've never had his issue, but I'm always suspicious of delimited names, and have no idea how they'll interact with the JDBC driver. Have you tried something similar with a non-delimited column name?
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64606
86
IntelliJ IDE Java jQuery Mac Mac OS X
 
Tom Reilly
Rancher
Posts: 618
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Assuming that your two queries are the same (which I'm not yet convinced), could you be accessing different databases? different schemas? different user?
 
Alexander Selling
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Have you tried something similar with a non-delimited column name?


Thing is I'm using an MSAccess database that came with a product that the family company bought, so I can't change their column names. However I imported their database into my MSSQL server and changed the column names on my copy of it, and just like you said, it will retrieve less results every time due to the space in the column name, because when I changed it from [KEY 1] to just KEY1, suddenly all the results came just fine. Now I don't know how to solve this, since I can't change the actual database that I want to read from, but at least now I know why

Thanks a lot!
 
David Newton
Author
Rancher
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It's even worse than that, because the JDBC-ODBC drivers have a lot of issues, so accessing the ironically-named Access may lead to even *more* troubles :)
 
Tom Reilly
Rancher
Posts: 618
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
How about creating views to "wrap" the tables?
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic