This week's book giveaways are in the Cloud and AI/ML forums.
We're giving away four copies each of Cloud Native Patterns and Natural Language Processing and have the authors on-line!
See this thread and this one for details.
Win a copy of Cloud Native PatternsE this week in the Cloud forum
or Natural Language Processing in the AI/ML forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Devaka Cooray
  • Liutauras Vilda
  • Jeanne Boyarsky
  • Bear Bibeault
Sheriffs:
  • Paul Clapham
  • Knute Snortum
  • Rob Spoor
Saloon Keepers:
  • Tim Moores
  • Ron McLeod
  • Piet Souris
  • Stephan van Hulst
  • Carey Brown
Bartenders:
  • Tim Holloway
  • Frits Walraven
  • Ganesh Patekar

JBDC connection and getAllOrders() method

 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
JBDC connection and getAllOrders() method

I have been writing a little APEX, but I was told it would be a good idea to learn JAVA before I continue with APEX. I created a JAVA application and I have a MySQL server / database to connect to. I created an Order Class, OrderDAO Class, and a ConnectionPOOL class. The Order class is the pojo. I'm trying to write a getAllOrders () method in the OrderDAO class (and UPDATE and DELETE), but I can't seem to get it to work. Would anyone mind taking a look?

MyConnectionPool
-----



Order Pojo





Order DAO

I'm getting an error with the statement s and catch?

-------

 
Saloon Keeper
Posts: 6037
58
Eclipse IDE Firefox Browser MySQL Database VI Editor Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Whenever you post code please surround it with Code tags. In the editor window highlight (select) your block of code and then click on the "Code" button just above the editor pane. I fixed it for you this time.
 
Carey Brown
Saloon Keeper
Posts: 6037
58
Eclipse IDE Firefox Browser MySQL Database VI Editor Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I expected to see something at line 20 in your OrderDAO class. You are iterating through "rs" but you are not doing anything with it.
 
Carey Brown
Saloon Keeper
Posts: 6037
58
Eclipse IDE Firefox Browser MySQL Database VI Editor Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If you run this from the MySQL command line utility what do you get? (first few lines)
 
Carey Brown
Saloon Keeper
Posts: 6037
58
Eclipse IDE Firefox Browser MySQL Database VI Editor Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Given this commented out line of code

I would expect your DAO class to have at least the following fields: id, name, and createdDate.
I would expect that you would construct a DAO object with the data in the result set.
I would expect the constructed DAOs to be gathered up in a List<OrderDAO>, and that this list would be returned from the method.
You should provide a toString() method to print out the state of the fields and then use that in place of this println() construct.

Edit: Went back to your code and I forgot that you had an "Order" class, so that should be used in my preceding comments.
 
Carey Brown
Saloon Keeper
Posts: 6037
58
Eclipse IDE Firefox Browser MySQL Database VI Editor Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!