Hello Everyone! Very close to completing my project but a small favor needed! Which is blocking me from finishing the last section of the project!

This is how it goes!!!!!

Have an Interface with inc complete methods

//OshwalDAO.java

void InsertLog(String LogID , String Username , java.Util.Date CurrentDate)
throws ClassNotFoundException , SQLException;

Have a DAO File which contains all code to perform database actions:

//DAO.java implements OshwalDAO.java

public void InsertLog (String LogID , String Username , java.util.Date CurrentDate)
      throws ClassNotFoundException , SQLException

{

     try
          {
            Statement SQLStatement = getDatabaseConnection();
            String SQLQuery = "INSERT INTO Logs (Username , LogDate) VALUES ('" + Username +"' , '" + CurrentDate+"')";
            SQLStatement.execureQuery(SQLQuery);
            DestroySQLConnection();

          }

      
     catch (ClassNotFoundException cnfe)
          {
            System.out.println(cnfe);
            throw cnfe;
          }

     catch (SQLException SQLE)
          {
            System.out.println(SQLE);
            throw SQLE;
          }

Now the servlet does the action calls the method.

LoginServlet.java

OshwalDAO Dao = DAO.getDAOInterface();

java.util.Date CurrentDate = new Date();

Dao.InsertLog(request.getparameter("Username") , CurrentDate);

response.sendRedirect("DateSuccessful.jsp");

This is the Code. The Error i get is syntax error in the SQL Statement.

All Help Appreciated.

Thank You!

Recommended Answers

All 3 Replies

1) I do wonder if you did direct copy or paste since your interface Date class is wrong java.Util.Date
2) You should have used java.sql.Date 3) I received up-vote from you for MVC tutorial, so I would have expected from you to use PreparedStatement instead of single & double quote hell
4) If you get exception it is always best to post exact error

commented: Thanks Friend for the useful post! :-) +3

Hey peter thanks! Gt the answer! used

java.sql.Date

thanks for the assistance. Sorry for the error did not do direct copy was writing the exact code from my program! So sorry for the grammatical errors since java is case sensitive.

I used the java.sql.Date and it worked! Want to thank u alot! Cheerz!

Yes i had upvoted for the MVC Tutorial! You Saved me with that tutorial! Its nice once again to learn from outstanding tutorials from you! Thank u for posting it!

:-) :-) :-) :-)

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.