This week's giveaway is in the JDBC forum.
We're giving away four copies of Java Database Connections & Transactions (e-book only) and have Marco Behler on-line!
See this thread for details.
Win a copy of Java Database Connections & Transactions (e-book only) this week in the JDBC 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
  • Knute Snortum
  • Paul Clapham
  • Tim Cooke
Sheriffs:
  • Liutauras Vilda
  • Jeanne Boyarsky
  • Bear Bibeault
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Ron McLeod
  • Piet Souris
  • Frits Walraven
Bartenders:
  • Ganesh Patekar
  • Tim Holloway
  • salvin francis

The DAO design pattern and its complexity  RSS feed

 
Ranch Hand
Posts: 210
1
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello, I decided to use the design pattern DAO to make queries with my database MySQL, I made the simplest on a table of three fields: index, name and first name. What is interesting is that the can quickly switch the Java app EE of a database: oracle, Mysql, mongoDB, and so on. This is because coding becomes more rigorous than queries without DAO design pattern. I did for the best under Eclipse luna but I have some mistakes that I do not understand, I put comments at the end of each lines or Eclipse highlights in red what Eclipse does not understand. I split my code into 4 modules for the DAO part and group the lines of codes in the controller: the servlet. For the DAO design pattern I use an interface to dialog with JDBC and end the database. I would like to be able to master this coding technique because it is necessary in larger projects. How to tell you that I pass a Java EE certification after attending a 3 months course, have me asking me to encode the DAO pattern design.


DaoExection.java

DaoFatory.java


UtilisateurDao.java


And now the errors gri gri ....



UtilisateurDaoImpl.java


The servlet



the JSP file



I expect you to work with a notion of pool because in good projects have to have several to develop under subversion. And especially something very important: I prefer code has an explanation in a technical peudo.


Best regards
Philippe
 
Marshal
Posts: 24499
55
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Well, I'm sorry but "// error on UtilisateurDaoImpl" isn't very helpful for somebody trying to help. I suppose it would be possible to dig through that long method and try to find out what the error message said, but it would be a lot easier if you just told us what the error message said in the first place.

You're using Eclipse? Click on the "Problems" tab and look under "Errors". Copy and paste the error message from there.
 
Philippe Ponceblanc
Ranch Hand
Posts: 210
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Paul Clapham wrote:
You're using Eclipse? Click on the "Problems" tab and look under "Errors". Copy and paste the error message from there.


Yes Paul I understand well that it is difficult to imagine what Eclipse returns as error mistakes. So I made copy / past so that you can debeugate my code, here it is done

UtilisateurDaoImpl.java



The servlet Db_Dao.java


Regards
Philippe
 
Bartender
Posts: 2286
95
Eclipse IDE Google Web Toolkit Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I think you should start writing shorter code if you have issues with syntaxes.

Although I havent looked at your entire code,


There is a bracket missing after daoFactory.
 
Paul Clapham
Marshal
Posts: 24499
55
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It's quite likely that many of your errors are caused by Salvin's missing bracket. And I agree with Salvin that you shouldn't write a hundred lines of code before you check the syntax.

Start from the outside and work inwards:



Don't continue until this compiles correctly. Then:



Then insert a method description:



Then insert the contents of that method... and so on. Otherwise you just have a big mess which you can't make sense of.

 
Philippe Ponceblanc
Ranch Hand
Posts: 210
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hello,
I corrected my brackets errors under <drjava>. I always have problems with methods that I do not understand but I put comments on errors with the complexion of eclipse luna.
Apparently my program does not link the descriptions of the methods and their implementations.
How to tell you for lack of experiences that I am in a dead end of which I can not get out of this last without help!

UtilisateurDaoImpl


The servlet Db_Dao.java

 
Paul Clapham
Marshal
Posts: 24499
55
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Right. Your brackets still don't match each other correctly. But again, you have written far too much code before checking that it compiles. What can I say that I haven't already said? Don't do that.
 
Master Rancher
Posts: 4087
47
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
One thing I will add.
You are using an IDE, and that IDE has an auto-format function (don't ask me exactly where as I can't remember).
Use it to format your code as your indentation is currently all over the place, and you are missing these basic errors because of that.

if, after formatting, the code layout looks wrong (eg methods are not starting near the left) then you know you have missed a bracket or two somewhere.
 
Marshal
Posts: 5995
156
Chrome Eclipse IDE Java Postgres Database Ubuntu VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I don't think DrJava has an auto-format function; at least I couldn't find one.
 
Dave Tolls
Master Rancher
Posts: 4087
47
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
In earlier posts he mentions using Eclipse (Luna in particular).
 
Knute Snortum
Marshal
Posts: 5995
156
Chrome Eclipse IDE Java Postgres Database Ubuntu VI Editor
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Okay, in Eclipse, auto-format is Ctrl-Alt-F.
 
Philippe Ponceblanc
Ranch Hand
Posts: 210
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello, I've worked on my program, I have a few errors that I do not know how to circumvent.
I went from Eclipse Luna to Eclipse Mars2, I share my errors in the following source code:
I'm still working on the design pattern DAO :


utilisateurDaoImpl.java







the servlet




I tried to do the maximum bug fixing in my code, I would like to be able to conclude because I must pass my certification.


Regards
Philippe
 
Dave Tolls
Master Rancher
Posts: 4087
47
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Your formatting is still incorrect.
Please use the inbuilt IDE tools to make your code easier to follow.

The first error (the DaoException one) is saying that any public class has to be in its own file of the same name.

The second error is saying that there is no request variable visible at that point.  Where is request declared?

The next (line 41) is you have a semi-colon in the wrong place.

The one after that (line 58) is saying that the only ajouter() method the compiler can find is one that takes a Utilisateur parameter, and you are calling it with no parameter at all.

The rest are similar issues, including another DaoException class in the Servlet (why?).
 
Philippe Ponceblanc
Ranch Hand
Posts: 210
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Your formatting is still incorrect.
Please use the inbuilt IDE tools to make your code easier to follow.  



have you an Url or link to learn has used the formatting tools of Eclipse Mars2.
 
Dave Tolls
Master Rancher
Posts: 4087
47
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
<CTRL> <SHIFT> F

Or it's under one of the menus.
 
Knute Snortum
Marshal
Posts: 5995
156
Chrome Eclipse IDE Java Postgres Database Ubuntu VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
In Eclipse Oxygen, it's under the Source menu.
 
Knute Snortum
Marshal
Posts: 5995
156
Chrome Eclipse IDE Java Postgres Database Ubuntu VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Let's continue any discussion about the JDK in Eclipse in the new topic I created.  
 
Philippe Ponceblanc
Ranch Hand
Posts: 210
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
After solving my problems under Eclipse Oxygen, I return to the Intranet I am currently developing.
I still have one error in my DAO implementation, the code below:





on the other hand, in my project I declared an interface to initiate methods, here is the code:


The servlet does not find this statement of my methods, carrying in the imports I declare this program java, here is the code:





I do not understand why in the servlet it returns errors (5 errors) whenever I call a method implemented in UserDaoImpl.java. it does not link to the declaration of methods and their implementations.
I have to forget parameters or occurrences in the methods without "void" but which occurences is missing?

the servlet codes do not change otherwise with the automatic formatting of eclipse.
 
Dave Tolls
Master Rancher
Posts: 4087
47
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What errors are you getting.
Post the full text here, and highlight which lines in your code they are occurring on.

A comment on the code.  Your SQLException catch block is empty.  At the least you should be logging the stack trace, otherwise you will never know there was an error, because there will be one...caused by line 14.  Your SQL is not returning the 'id', so attempting to get the id from the result set will fail.

Also, line 19.  I would have thought your would want to use the id from the noms table?  And I would expect that id to be a number of some sort, not a String.
 
Knute Snortum
Marshal
Posts: 5995
156
Chrome Eclipse IDE Java Postgres Database Ubuntu VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
In line 19, the compiler can't find the object request.  Since it's not a local variable, where is it declared?
 
Knute Snortum
Marshal
Posts: 5995
156
Chrome Eclipse IDE Java Postgres Database Ubuntu VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
See my comments:
 
Knute Snortum
Marshal
Posts: 5995
156
Chrome Eclipse IDE Java Postgres Database Ubuntu VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The error message seems pretty clear.  There is no method ajouter() that takes no arguments.  There is one that takes one argument, though: ajouter(Utilisateur).  The class is UtilisateurDao.
 
Danger, 10,000 volts, very electic .... tiny ad:
how do I do my own kindle-like thing - without amazon
https://coderanch.com/t/711421/engineering/kindle-amazon
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!