This week's book giveaway is in the OCMJEA forum.
We're giving away four copies of OCM Java EE 6 Enterprise Architect Exam Guide and have Paul Allen & Joseph Bambara on-line!
See this thread for details.
The moose likes JDBC and the fly likes problem in Access database. Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of OCM Java EE 6 Enterprise Architect Exam Guide this week in the OCMJEA forum!
JavaRanch » Java Forums » Databases » JDBC
Bookmark "problem in Access database." Watch "problem in Access database." New topic
Author

problem in Access database.

Punit Jain
Ranch Hand

Joined: Aug 20, 2011
Posts: 998
    
    2
i have a table in msAccess one column in that table has a datatype number.
but when i m fetching the value from database, this field value is not coming from my db, it showing me exception:


but my data is exist in that column in table..

also i want to know, if my table is table(access) is opened it will not run my project.
what i need to do if i want to run my project, even if my table is opened??

Thank you..
Wendy Gibbons
Bartender

Joined: Oct 21, 2008
Posts: 1107

Punit, we are going to need to see the select statement, and you will need to run it against the database using a viewer as well
Punit Jain
Ranch Hand

Joined: Aug 20, 2011
Posts: 998
    
    2
here is my function to fetch records:


and here i am displaying all the records:


it displaying all the records except the int values, this one: txtFeeDue.setText(String.valueOf(res.getInt(14)));
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19685
    
  20

Are you sure your table has at least 18 columns?
You should never use SELECT *. It doesn't tell you which columns are returned, but more importantly, it also guarantees no order. If you add another column between two existing columns, all your logic will break. So just mention all the columns you want in the SELECT statement.


SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6
How To Ask Questions How To Answer Questions
Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18541
    
    8

Punit Jain wrote:it displaying all the records except the int values, this one: txtFeeDue.setText(String.valueOf(res.getInt(14)));


And is that because the exception you originally mentioned is still being thrown? Or is that field just not appearing?

In the latter case it's probably because you're writing the data to a component which isn't in the GUI:


William P O'Sullivan
Ranch Hand

Joined: Mar 28, 2012
Posts: 859

Paul has it I think..

You need to add that txtField to the panel or container or whatever.

Also you should change your select to something like "select col1,col2,col3 from ..."
then in the Java code access the rs using:


This gives you much greater control over future DB changes and unforeseen ordering changes,
such as alter table add colx after col2 etc..

WP
Tim Moores
Rancher

Joined: Sep 21, 2011
Posts: 2408
java.sql.SQLException: No data found

That is an awesome error message.
Punit Jain
Ranch Hand

Joined: Aug 20, 2011
Posts: 998
    
    2

Are you sure your table has at least 18 columns?

yes

You should never use SELECT *. It doesn't tell you which columns are returned, but more importantly, it also guarantees no order. If you add another column between two existing columns, all your logic will break. So just mention all the columns you want in the SELECT statement.

i have changed * to all my column names.
Punit Jain
Ranch Hand

Joined: Aug 20, 2011
Posts: 998
    
    2

And is that because the exception you originally mentioned is still being thrown? Or is that field just not appearing?

if i m trying to print that value, it showing me exception.
but i m just adding that value to textBox, it not showing me exception, but also no data appear in that field.


In the latter case it's probably because you're writing the data to a component which isn't in the GUI:


what do you mean by this?
you mean that i have not declared txtFeeDue, but i have declared it in my code, i have not posted my whole code..
Punit Jain
Ranch Hand

Joined: Aug 20, 2011
Posts: 998
    
    2

You need to add that txtField to the panel or container or whatever.

but i m doing this:



Also you should change your select to something like "select col1,col2,col3 from ..."
then in the Java code access the rs using:


done, still the problem is same.
Punit Jain
Ranch Hand

Joined: Aug 20, 2011
Posts: 998
    
    2
i have also changed the type to string, but still it showing me the same exception, might be the problem is somewhere in my code..
my search class has arround 430 lines of code, should i post that here??
Punit Jain
Ranch Hand

Joined: Aug 20, 2011
Posts: 998
    
    2
okay...
it's working..
i have changed my datatype to string..
also i was initializing my jtextfield twice..

Thank you all....
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: problem in Access database.