• 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

design pattern DAO

 
Ranch Hand
Posts: 210
1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hello, for a new project, it's like a youtube but with the possibility to translate into several languages each video. I use patern design DAO, so I made several class in the package com.openclassrooms.dao. *
In my implementation of methods I have errors that arise in my class videoDaoIplm.java.
here is my code:





I would like to understand why it displays this error, while the other methods do not display errors?

Regards
Philippe
 
Marshal
Posts: 8857
637
Mac OS X VI Editor BSD Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Maybe worth to include error messages you are getting so the guys wouldn't need to guess, please.
 
Philippe Ponceblanc
Ranch Hand
Posts: 210
1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Liutauras Vilda wrote:Maybe worth to include error messages you are getting so the guys wouldn't need to guess, please.



but I tell you where the errors of my program are thanks to the tag "//"
I do not understand the meaning of your question and I have not compiled the code!
 
Liutauras Vilda
Marshal
Posts: 8857
637
Mac OS X VI Editor BSD Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Philippe Ponceblanc wrote:but I tell you where the errors of my program are


But I ask you what the errors are (would have to thank to stack traces).
 
Liutauras Vilda
Marshal
Posts: 8857
637
Mac OS X VI Editor BSD Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Philippe Ponceblanc wrote: do not understand the meaning of your question


Usually when people experiencing some compilation errors or run-time exceptions we usually ask them to provide stack traces.
Stack traces pretty clearly identify the exact problem(s).

In short - if stack trace says i.e.:

That means you possibly don't have declared such method as getConnection() (not saying it is your problem currently), or got some typo either in a method call or method declaration.

Is clearer now?
 
Saloon Keeper
Posts: 10705
86
Eclipse IDE Firefox Browser MySQL Database VI Editor Java Windows ChatGPT
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You crreate a "Video" (upper-case-V) object called "video" (lower-case-v). The problem with the error lines is that you need to call the setter methods on the object, not on the class.
 
Philippe Ponceblanc
Ranch Hand
Posts: 210
1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hello,
i anderstand !



Creates a Statement object for sending SQL statements to the database. SQL statements without parameters are normally executed using Statement objects. If the same SQL statement is executed many times, it may be more efficient to use a PreparedStatement object.

Result sets created using the returned Statement object will by default be type TYPE_FORWARD_ONLY and have a concurrency level of CONCUR_READ_ONLY. The holdability of the created result sets can be determined by calling getHoldability.

Returns:
a new default Statement object
Throws:
SQLException - if a database access error occurs or this method is called on a closed connection






The method setfichier(String) is undefined for the type Video





The method add(Video) is undefined for the type Video

 
Marshal
Posts: 28193
95
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Your error messages are all about the class Video, and you haven't posted the code for that class. So again we are forced to guess.

The error messages say that there are no static methods in the class Video which have those names. So we don't have to guess about that. But the names you used are normally used for instance methods, so we could guess that you did that. And if you did, and you expected them to be used in that code, well... somebody already posted that you're calling them on the class Video and not the variable video.

By the way, those setter methods: in the standard JavaBean style you would call them setFichier and not setfichier, and so on.
 
Philippe Ponceblanc
Ranch Hand
Posts: 210
1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
this the video class with setter and getter




DaoFactory.java


VideoDao



videoDaoImpl.java all code


 
Carey Brown
Saloon Keeper
Posts: 10705
86
Eclipse IDE Firefox Browser MySQL Database VI Editor Java Windows ChatGPT
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You've been told whats wrong with this code. Time to get it right.
 
Philippe Ponceblanc
Ranch Hand
Posts: 210
1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hello Paul Clapham,
Your error messages are all about the Video class and you have not released the code for this class. Once again we have to guess.

>> Now you have the video class, and I wonder why it takes static methods?

The error messages indicate that there are no static methods in the Video class that have these names. So we do not have to guess about it.
>> yes you understand!

But the names you used are normally used for example methods, so we might guess that you did that.
>> I am inspired by the model DAO of my course that I am!

And if you did, and you expected them to be used in this code,

>> here I do not understand I just want to know:
>> 1 / the path and file name to load the right video!
>> 2 / I do not understand this sentence?
well ... someone has already posted that you call them on the video of the class and not on the variable video.
>> I do not mix the class and variabbles I'm not so stupid

By the way, these setter methods: in the standard JavaBean style, you would call them setFile and not setfile, and so on.

>> here I understand that I made annotation errors!

DAO> now that I've been writing for a long time that you have to create an interface, then declare the methods and finally implement the methods it's like in C ++.

but it's not so obvious that it may seem

how do you also say that a CAD design pattern is not easy to set up

and especially a piece of code and often more understanding than to speak is like drawing a picture to explain


so explain me please
Regards
philippe
 
Rancher
Posts: 4801
50
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Taking the bit of code Carey posted above.



In the first line you create a Video object and assign the reference to the video variable.
Then on the second line you do not use the video variable...you are using the Video class name.
The compiler thinks you want to run a static method called setfichier that is part of the Video class.
This looks like a typo, and you actually wanted to use the video variable and not the class.
 
Philippe Ponceblanc
Ranch Hand
Posts: 210
1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
in VideoFactory i have add an static methode, like this :


in VideoDaoImpl ihave do like you says me; it's works !


i have juste one error on VideoDaoImpl

 
Carey Brown
Saloon Keeper
Posts: 10705
86
Eclipse IDE Firefox Browser MySQL Database VI Editor Java Windows ChatGPT
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Philippe Ponceblanc wrote:i have juste one error on VideoDaoImpl


Your VideoDaoImpl class doesn't have an add() method defined.
 
Carey Brown
Saloon Keeper
Posts: 10705
86
Eclipse IDE Firefox Browser MySQL Database VI Editor Java Windows ChatGPT
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Carey Brown wrote:

Philippe Ponceblanc wrote:i have juste one error on VideoDaoImpl


Your VideoDaoImpl class doesn't have an add() method defined.


You probably meant
 
Philippe Ponceblanc
Ranch Hand
Posts: 210
1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
i have add the methode in bean.Video.java


now I have a 500 error:


in line 62 i have this code ;



in the servlet ligne 47 :


 
Dave Tolls
Rancher
Posts: 4801
50
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
That means that the connexion variable is null.
Which means that getConnection is returning null...which is what the code you gave earlier is doing.
 
Philippe Ponceblanc
Ranch Hand
Posts: 210
1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
in the beans package i have do like this:




and now, i have yet 500 error !






and


I still have trouble decrypting 500 errors
 
Carey Brown
Saloon Keeper
Posts: 10705
86
Eclipse IDE Firefox Browser MySQL Database VI Editor Java Windows ChatGPT
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Philippe Ponceblanc wrote:in VideoFactory i have add an static methode, like this :

Have your replaced the body of this method? What does it look like?
 
Philippe Ponceblanc
Ranch Hand
Posts: 210
1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

I'm nothing done in this method, I'm sure there is something to do with hands I do not know!
This is the first time I use "static" methods in JavaEE.

what should you do to return an argument instead of null?



it's not VideoFactory but DaoFactory, this is where I put the parameter statement for connection with MySql!

here is the complete code of DaoFactory, I repeat myself! lol


 
Carey Brown
Saloon Keeper
Posts: 10705
86
Eclipse IDE Firefox Browser MySQL Database VI Editor Java Windows ChatGPT
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Look up the DriverManager class. There are a few getConnection() methods to choose from.
 
Philippe Ponceblanc
Ranch Hand
Posts: 210
1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Carey Brown wrote:Look up the DriverManager class. There are a few getConnection() methods to choose from.



Hello,
I read your documentation and I am aware that 'getconnection' is already declared in the DaoFactory and my implementation class (VideoDaoImpl) does not take into account Daofoctory, why it does not make the link between the two class java c is DaoFactory and VideoDaoIml; I do not understand why he does not make the link while they are both in the same package?
 
Philippe Ponceblanc
Ranch Hand
Posts: 210
1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
finaly i do like this ;

 
Carey Brown
Saloon Keeper
Posts: 10705
86
Eclipse IDE Firefox Browser MySQL Database VI Editor Java Windows ChatGPT
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
That method just calls itself which means you'll probably get an out of memory exception. You need to call one of the methods in DriverManager.
 
Carey Brown
Saloon Keeper
Posts: 10705
86
Eclipse IDE Firefox Browser MySQL Database VI Editor Java Windows ChatGPT
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Example

 
Philippe Ponceblanc
Ranch Hand
Posts: 210
1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
ihave error on   props.put

The method put(String, String) is undefined for the type Properties




 
Paul Clapham
Marshal
Posts: 28193
95
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The method you're looking for isn't called "put". Have a look at the API documentation for the Properties class to find out what it really is called.

You'll find a link to the documentation for all sorts of Java versions here: https://docs.oracle.com/javase/8/docs/api/ and you can click on the link there to go to the version you use.
 
Paul Clapham
Marshal
Posts: 28193
95
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
And this "Properties" class: it is java.util.Properties, isn't it?
 
Carey Brown
Saloon Keeper
Posts: 10705
86
Eclipse IDE Firefox Browser MySQL Database VI Editor Java Windows ChatGPT
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Ah, it's "setProperty()" but because Properties is a subclass of Hashtable which has put(), my compile has worked and run for many years. Even compiling with Java 9 hasn't been an issue. (?)
I changed mine to setProperty() because that's the correct one to use but I don't know why no problems showed up with put().
 
Carey Brown
Saloon Keeper
Posts: 10705
86
Eclipse IDE Firefox Browser MySQL Database VI Editor Java Windows ChatGPT
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Paul Clapham wrote:And this "Properties" class: it is java.util.Properties, isn't it?

Yes.
 
Carey Brown
Saloon Keeper
Posts: 10705
86
Eclipse IDE Firefox Browser MySQL Database VI Editor Java Windows ChatGPT
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Properties inherits from Hashtable<Object,Object> so a put() of <String,String> seems to work. (At least for me. Though setProperty() is the correct one to use.)
 
Paul Clapham
Marshal
Posts: 28193
95
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Carey Brown wrote:

Paul Clapham wrote:And this "Properties" class: it is java.util.Properties, isn't it?

Yes.



I asked because I didn't see any import statement for Properties. And also because after I posted my first response, I realized that the put(String, String) method should compile successfully. So that led me to suspect that some other Properties file had inadvertently been used.
 
Carey Brown
Saloon Keeper
Posts: 10705
86
Eclipse IDE Firefox Browser MySQL Database VI Editor Java Windows ChatGPT
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Philippe, what do your imports look like?
 
Philippe Ponceblanc
Ranch Hand
Posts: 210
1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Carey Brown wrote:Philippe, what do your imports look like?




 
Carey Brown
Saloon Keeper
Posts: 10705
86
Eclipse IDE Firefox Browser MySQL Database VI Editor Java Windows ChatGPT
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Philippe Ponceblanc wrote:import com.sun.javafx.scene.control.Properties;


Ah, you're importing the wrong Properties. Change to
java.util.Properties
 
Philippe Ponceblanc
Ranch Hand
Posts: 210
1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
thanks you carey !

just the last errors, if i chaange set fichier to setFichier all the ligne is on errors !

 
Philippe Ponceblanc
Ranch Hand
Posts: 210
1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator


getConnection() yet error, I do not understand anymore because the completion write me create a method getConnection,
as if he does not support what have just been done
 
Philippe Ponceblanc
Ranch Hand
Posts: 210
1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
this still my code :

DaoFoctory




VideoDaoImpl

 
Carey Brown
Saloon Keeper
Posts: 10705
86
Eclipse IDE Firefox Browser MySQL Database VI Editor Java Windows ChatGPT
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
When you have static methods in a class you call it by using the class name, dot (.), method name. In your case the class name is "Video" with an upper case "V". However your set methods are not static and only apply to an instance of your class, you have that instance, it's name is "video" with a lower case  "v". So, just change them to
An add() method is "usually" used to add an instance to a collection. Your collection is a List<Video> whose name is "videos" with a lower case "v". So to add your new "video" instance to your "videos" list you need
(Haven't we been here before?)

What does this do?
 
Carey Brown
Saloon Keeper
Posts: 10705
86
Eclipse IDE Firefox Browser MySQL Database VI Editor Java Windows ChatGPT
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Carey Brown wrote:You crreate a "Video" (upper-case-V) object called "video" (lower-case-v). The problem with the error lines is that you need to call the setter methods on the object, not on the class.

 
reply
    Bookmark Topic Watch Topic
  • New Topic