• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Can't find column

 
Kees deVries
Greenhorn
Posts: 23
  • Mark post as helpful
  • send pies
  • 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?
 
Tim Cooke
Sheriff
Pie
Posts: 3203
142
Clojure IntelliJ IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You are only selecting "tableNR" from the database. Not "orderID" (assuming there is such a column).
 
Brian Tkatch
Bartender
Posts: 567
25
Linux Notepad Oracle
  • Mark post as helpful
  • send pies
  • 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
  • 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: 567
25
Linux Notepad Oracle
  • Mark post as helpful
  • send pies
  • 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.
 
Roel De Nijs
Sheriff
Posts: 10662
144
AngularJS Chrome Eclipse IDE Hibernate Java jQuery MySQL Database Spring Tomcat Server
  • Mark post as helpful
  • send pies
  • 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: 10662
144
AngularJS Chrome Eclipse IDE Hibernate Java jQuery MySQL Database Spring Tomcat Server
  • Mark post as helpful
  • send pies
  • 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
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic