• 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 Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Can't find column

 
Greenhorn
Posts: 23
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
So, what the title says.


this fetches things from the database.



use this to get all the table numbers.

says it can't find the column "orderID"

anyone knows why?
 
Sheriff
Posts: 5555
326
IntelliJ IDE Python Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You are only selecting "tableNR" from the database. Not "orderID" (assuming there is such a column).
 
Bartender
Posts: 598
26
Oracle Notepad Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
is only selecting one column. Perhaps you should add orderID to your query.
 
Kees deVries
Greenhorn
Posts: 23
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Brian Tkatch wrote: is only selecting one column. Perhaps you should add orderID to your query.



But what if i only what all the tableNR? Or do i HAVE to select everything that i'm also getting in the selectOrder method?
 
Brian Tkatch
Bartender
Posts: 598
26
Oracle Notepad Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Kees deVries wrote:But what if i only what all the tableNR? Or do i HAVE to select everything that i'm also getting in the selectOrder method?


When the database processes a select statement, it creates an implicit cursor to hold the resultant data set. When you access the results, you are not accessing the table, you only have access to the implicit cursor. So, regardless of what data you want, the only columns that will be available are those mentioned in the select statement.
 
Sheriff
Posts: 11604
178
Hibernate jQuery Eclipse IDE Spring MySQL Database AngularJS Tomcat Server Chrome Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Kees deVries wrote:But what if i only what all the tableNR? Or do i HAVE to select everything that i'm also getting in the selectOrder method?


There is nothing wrong with only getting tableNR, but then you can't retrieve the value for column orderID as you currently do in the selectOrder method.

And based on the code of the selectOrder method, you definitely need the value of the orderID column. Otherwise you won't be able to retrieve the list of OrderProduct objects. Therefore you'll need to update your query to

Hope it helps!
Kind regards,
Roel
 
Roel De Nijs
Sheriff
Posts: 11604
178
Hibernate jQuery Eclipse IDE Spring MySQL Database AngularJS Tomcat Server Chrome Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Kees deVries wrote:use this to get all the table numbers.


I also have a few remarks about the overall quality of your code.

First of all, I don't get why the selectOrder method has to throw ClassNotFoundException I assume it is probably because of the call to super.getConnection(). It's probably because in that method you have something likeIf you are using a JDBC 4.0 compliant driver, you no longer need to explicitly load JDBC drivers using Class.forName(). The JDBC drivers are automatically loaded during initialitzation, thanks to the Java SE Service Provider mechanism (SPM). So you can remove this line from this method (and remove the throws clause as well) and the code will still work as intended.

Secondly you should not have code like thisBecause this code exposes an implementation detail (the class Order has probably a List of OrderProducts) and makes it harder to refactor the code. For example, if you need to change the type of the orderProducts property to an array or a Map, this code fails to compile and you need to update this code as well. It is much better to define a method addOrderProducts (or addProducts)) and this method takes care of adding the products. Using this approach you are not exposing any implementation details and if you need to change the type of the orderProducts property to e.g. a Map, you only need to change this method (and not the method in your DAO class).And then in the selectOrder method you can simply invoke this method

Hope it helps!
Kind regards,
Roel
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic