[Logo]
Forums Register Login
design pattern DAO
(0 likes, 1 cow)
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
Maybe worth to include error messages you are getting so the guys wouldn't need to guess, please.
 

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!
 

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).
 

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?
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.
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

 
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.
this the video class with setter and getter




DaoFactory.java


VideoDao



videoDaoImpl.java all code


You've been told whats wrong with this code. Time to get it right.
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
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.
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

 

Philippe Ponceblanc wrote:i have juste one error on VideoDaoImpl


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

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
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 :


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.
in the beans package i have do like this:




and now, i have yet 500 error !






and


I still have trouble decrypting 500 errors
 

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?

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


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

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?
finaly i do like this ;

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.
Example

ihave error on   props.put

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




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.
And this "Properties" class: it is java.util.Properties, isn't it?
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().
 

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

Yes.
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.)
 

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.
Philippe, what do your imports look like?
 

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




 

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


Ah, you're importing the wrong Properties. Change to
java.util.Properties
thanks you carey !

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



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
this still my code :

DaoFoctory




VideoDaoImpl

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 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.

 

This thread has been viewed 1322 times.

All times above are in ranch (not your local) time.
The current ranch time is
Oct 18, 2018 14:53:59.