aspose file tools*
The moose likes JDBC and the fly likes how to connect to database in java class and fetch the database table Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Databases » JDBC
Bookmark "how to connect to database in java class and fetch the database table" Watch "how to connect to database in java class and fetch the database table" New topic
Author

how to connect to database in java class and fetch the database table

aish sharma
Greenhorn

Joined: Mar 06, 2012
Posts: 10
Hi All,

NOTE:Please read the below data carefully.

I am having littlebit idea about java, not in detail. I am having an problm with database connectivity from java class and fetch the table of database.

Please see the below code, i can run the static data but i want convert it in to dynamic so please help me.i am getting an error.I amtrying to implement the below code in ZK framework. And mainPage.zul contains the code. for more clarification you can see the link "http://www.zkoss.org/zkdemo/grid/hierarchy" but here iwant to connect it to the database.








for database connectivity changes, i have tried to modify the above code but i am getting null pointer exception,





please help me to solve the above problm
Sumit Patil
Ranch Hand

Joined: May 25, 2009
Posts: 296

Can you post the full error message you are getting?


Thanks & Regards, Sumeet
SCJP 1.4, SCWCD 5, LinkedIn Profile
aish sharma
Greenhorn

Joined: Mar 06, 2012
Posts: 10
please see the below error.


aish sharma
Greenhorn

Joined: Mar 06, 2012
Posts: 10
Sumit Patil wrote:Can you post the full error message you are getting?


Hi Sumit , thanks for trying to help me .please see the above error
Sumit Patil
Ranch Hand

Joined: May 25, 2009
Posts: 296

Hi Aish,

I tried to analyze your code, but it seems, its out of my scope.

The error message states

" SEVERE: >>org.zkoss.zel.PropertyNotFoundException: Property '0' not found on type demo.grid.hierarchy.Customer "

I guess, the property '0' is not set in customer class in your code, since you are using it in your mainPage, try replacing this 0 with some property in the Customer class.

Not sure this will helps or not.
aish sharma
Greenhorn

Joined: Mar 06, 2012
Posts: 10
Sumit Patil wrote:Hi Aish,

I tried to analyze your code, but it seems, its out of my scope.

The error message states

" SEVERE: >>org.zkoss.zel.PropertyNotFoundException: Property '0' not found on type demo.grid.hierarchy.Customer "

I guess, the property '0' is not set in customer class in your code, since you are using it in your mainPage, try replacing this 0 with some property in the Customer class.

Not sure this will helps or not.




ok np...

i hv just debug the code and got to know my problm but not getting the solution.


please look the below two codes one is from static data which is executing correctly and one is dynamic(i.e from database) having the problm at the last line. if you can try again that will very helpful to me.

see the two code difference i am trying to make it dynamic


static code-





dynamic data(i.e from database)




i above my code is executing fine up to while staement . only there is an problm with

if you can correct this line that will solve my problm.
aish sharma
Greenhorn

Joined: Mar 06, 2012
Posts: 10


its not executing the above line it directly goes to the
Wendy Gibbons
Bartender

Joined: Oct 21, 2008
Posts: 1107

I am moving this to the JDBC forum, where all those chaps live/.
But my first thoughts.
you are not handling any exceptions and the close statements should be in a finally block.
Sumit Patil
Ranch Hand

Joined: May 25, 2009
Posts: 296

aish sharma wrote:

its not executing the above line it directly goes to the


Hi,

As Wendy suggested, put catch blocks and also put all those close statements in the finally block.
As you said, the code flow is going directly going to s.close, it means the resultset you are getting does not have any results from the sql you have fired. Please do check the table in the database. Also try putting SOP in the code to see where exactly it goes.
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: how to connect to database in java class and fetch the database table