943,706 Members | Top Members by Rank

Ad:
  • JSP Discussion Thread
  • Unsolved
  • Views: 2425
  • JSP RSS
You are currently viewing page 2 of this multi-page discussion thread; Jump to the first page
Sep 17th, 2009
0

Re: JSP database connectivity

cause u would need quotation marks. when comparing values from a table where the column is not of type numeric, u have to use quotation marks like this:
JSP Syntax (Toggle Plain Text)
  1. username=10101010 and password = 'StealthProject'

if username is an alphanumeric column type then that too will need quotation marks as well.

I suggest googling some basic select statements to see how to write sql statements.
Reputation Points: 36
Solved Threads: 57
Posting Whiz
Thirusha is offline Offline
355 posts
since Mar 2008
Sep 18th, 2009
0

Re: JSP database connectivity

Topic
The topic of this question is: jsp database connectivity ServletWrapper
Hello and Thank you in advance for any assistance.

System info:

Netbeans6.7.1,jsf1.2,MySQL(Web app).Model view Controller(MVC )Model 2.

The purpose of this post is:

As it turns out the supplied stmt is good after all but something is wrong with how the servlet is being handled I think . So I need to understand the error produced after logging in to database and all param’s are good(See note to see System.out.println code life cycle.

The functionality of this code is:

tutorial description found at:
http://www.daniweb.com/forums/thread141776.html
My netbeans project school can be found at:
http://cid-b5cb457363230793.skydrive...lic/school.zip

My question concerning this code is:

1.What is the purpose of the “+” in the sql stmt. Is this basic SQL? Or is it for the Java?
2.Could someone describe what I should be looking at concerning fixing the error?

The errors related to this code are:


Error description: http browser page:Error

JSP Syntax (Toggle Plain Text)
  1. HTTP Status 500 -
  2.  
  3. type Exception report
  4.  
  5. message
  6.  
  7. descriptionThe server encountered an internal error () that prevented it from fulfilling this request.
  8.  
  9. exception
  10.  
  11. java.lang.UnsupportedOperationException: Not yet implemented
  12.  
  13. note The full stack traces of the exception and its root causes are available in the Sun GlassFish Enterprise Server v2.1 logs.
  14. Sun GlassFish Enterprise Server v2.1

Note: Please find code below of program life cycle and where it blew out.



Error description: System.out.println code life cycle. And where it died!

JSP Syntax (Toggle Plain Text)
  1. Initializing Sun's JavaServer Faces implementation (1.2_04-b22-p05) for context '/school'
  2. LoginServlet Init()<------------>Class.forName(config.getInitParameter('jdbcDriver')).toString<------------>Initialized the connector String
  3. LoginServlet Init()<------------>created a new UserBean object<------------>
  4. UserBean()<------------>in userbean constructor<------------>constructor
  5. %in getUserData()-------------->10101010<--------------userName%
  6. %in getUserData()-------------->StealthProject<--------------passwored %
  7. UserBean()<------------>in userbean constructor<------------>constructor
  8. connected to db--------->%com.mysql.jdbc.JDBC4Connection@1138a28%<----------------connection
  9. UserBean getUserData()-------------->%SELECT u.uid, firstName, lastName, address1, address2, city, postCode, email,phone, ug.groupName as userGroup FROM user u, usergroup ug WHERE uid='10101010' AND password='StealthProject' AND groupName IN (SELECT groupName FROM usergroup WHERE groupid =(SELECT groupid FROM usergroup_mapping WHERE uid=u.uid))%<--------------my new strQuery (I created
  10. %-------------->com.mysql.jdbc.StatementImpl@1d36fa0<--------------stmt%
  11. %-------------->com.mysql.jdbc.JDBC4ResultSet@1506a1e<--------------rs%
  12. UserBean()<------------>10101010<------------>uid from setter
  13. UserBean()<------------>Patrick<------------>FirstName from setter
  14. UserBean()<------------>Naughton<------------> Last Name from setter
  15. UserBean()<------------>Cromwell Road<------------>Address1 from setter
  16. UserBean()<------------>null<------------>address2 from setter
  17. UserBean()<------------>London<------------>City from setter
  18. UserBean()<------------>C19 90J<------------>post Code from setter
  19. UserBean()<------------>p.naughton@dwtutorial.com<------------>Email from setter
  20. UserBean()<------------>19770814<------------>Phone from setter
  21. UserBean()<------------>admin<------------> UserGroup from setter
  22. dataManager.getUserData()-------------->%10101010%<--------------getParameter(userName)
  23. dataManager.getUserData()-------------->%StealthProject%<--------------getParameter(passsword)
  24. doPost()-------------->%true%<--------------dbOk
  25. StandardWrapperValve[LoginServlet]: PWC1406: Servlet.service() for servlet LoginServlet threw exception
  26. java.lang.UnsupportedOperationException: Not yet implemented
  27. at model.DataManager.getUsersList(DataManager.java:123)
  28. at servlets.LoginServlet.doPost(LoginServlet.java:129)
  29.  

Thanks again.
-ceyesuma
Reputation Points: 7
Solved Threads: 2
Posting Pro
ceyesuma is offline Offline
524 posts
since Aug 2007
Sep 18th, 2009
-1

Re: JSP database connectivity

The plus in query uid='"+userName+"' is part of Java as you are building SQL query from simple string. The value provided between single and double quotes and plus is a value that you either retrieved from user or received by previous computation. Consider it as small plus point on the list why to use PreparedStatement instead of basic query

As for second problem I have no idea as you neither provided log file as suggested to look into by error message, neither you provided relevant code with pointing which section is working and where you getting error
Moderator
Featured Poster
Reputation Points: 2786
Solved Threads: 871
Code tags enforcer
peter_budo is offline Offline
6,655 posts
since Dec 2004
Sep 18th, 2009
0

Re: JSP database connectivity

Topic
The topic of this question is: reply_servlet_wrapper
Hello and Thank you in advance for any assistance.

The purpose of this post is:

Thanks peter_budo for the reply and the tutorial I might add.

I an not farmiliar with the log you mentioned. I did trace program output where it shows the program makes it to the doPost() of the LoginServlet.java.
Program at school.zip:
http://cid-b5cb457363230793.skydrive...lic/school.zip

The errors related to this code are:



Error description:trace program progress and error (Note: doPost() dbOK=true)

JSP Syntax (Toggle Plain Text)
  1. Initializing Sun's JavaServer Faces implementation (1.2_04-b22-p05) for context '/school'
  2. LoginServlet Init()<------------>Class.forName(config.getInitParameter('jdbcDriver')).toString<------------>Initialized the connector String
  3. LoginServlet Init()<------------>created a new UserBean object<------------>
  4. UserBean()<------------>in userbean constructor<------------>constructor
  5. %in getUserData()-------------->10101010<--------------userName%
  6. %in getUserData()-------------->StealthProject<--------------passwored %
  7. UserBean()<------------>in userbean constructor<------------>constructor
  8. connected to db--------->%com.mysql.jdbc.JDBC4Connection@1401ab6%<----------------connection
  9. UserBean getUserData()-------------->%SELECT u.uid, firstName, lastName, address1, address2, city, postCode, email,phone, ug.groupName as userGroup FROM user u, usergroup ug WHERE uid='10101010' AND password='StealthProject' AND groupName IN (SELECT groupName FROM usergroup WHERE groupid =(SELECT groupid FROM usergroup_mapping WHERE uid=u.uid))%<--------------my new strQuery (I created
  10. %-------------->com.mysql.jdbc.StatementImpl@199c538<--------------stmt%
  11. %-------------->com.mysql.jdbc.JDBC4ResultSet@14b1500<--------------rs%
  12. UserBean()<------------>10101010<------------>uid from setter
  13. UserBean()<------------>Patrick<------------>FirstName from setter
  14. UserBean()<------------>Naughton<------------> Last Name from setter
  15. UserBean()<------------>Cromwell Road<------------>Address1 from setter
  16. UserBean()<------------>null<------------>address2 from setter
  17. UserBean()<------------>London<------------>City from setter
  18. UserBean()<------------>C19 90J<------------>post Code from setter
  19. UserBean()<------------>p.naughton@dwtutorial.com<------------>Email from setter
  20. UserBean()<------------>19770814<------------>Phone from setter
  21. UserBean()<------------>admin<------------> UserGroup from setter
  22. dataManager.getUserData()-------------->%10101010%<--------------getParameter(userName)
  23. dataManager.getUserData()-------------->%StealthProject%<--------------getParameter(passsword)
  24. doPost()-------------->%true%<--------------dbOk
  25. StandardWrapperValve[LoginServlet]: PWC1406: Servlet.service() for servlet LoginServlet threw exception
  26. java.lang.UnsupportedOperationException: Not yet implemented
  27. at model.DataManager.getUsersList(DataManager.java:123)
  28. at servlets.LoginServlet.doPost(LoginServlet.java:129)
  29. at javax.servlet.http.HttpServlet.service(HttpServlet.java:754)
  30. at javax.servlet.http.HttpServlet.service(HttpServlet.java:847)
  31. at org.apache.catalina.core.ApplicationFilterChain.servletService(ApplicationFilterChain.java:427)
  32. at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:315)
  33. at org.apache.catalina.core.StandardContextValve.invokeInternal(StandardContextValve.java:287)
  34. at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:218)
  35. at org.apache.catalina.core.StandardPipeline.doInvoke(StandardPipeline.java:648)
  36. at org.apache.catalina.core.StandardPipeline.doInvoke(StandardPipeline.java:593)
  37. at com.sun.enterprise.web.WebPipeline.invoke(WebPipeline.java:94)
  38. at com.sun.enterprise.web.PESessionLockingStandardPipeline.invoke(PESessionLockingStandardPipeline.java:98)
  39. at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:222)
  40. at org.apache.catalina.core.StandardPipeline.doInvoke(StandardPipeline.java:648)
  41. at org.apache.catalina.core.StandardPipeline.doInvoke(StandardPipeline.java:593)
  42. at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:587)
  43. at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:1096)
  44. at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:166)
  45. at org.apache.catalina.core.StandardPipeline.doInvoke(StandardPipeline.java:648)
  46. at org.apache.catalina.core.StandardPipeline.doInvoke(StandardPipeline.java:593)
  47. at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:587)
  48. at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:1096)
  49. at org.apache.coyote.tomcat5.CoyoteAdapter.service(CoyoteAdapter.java:288)
  50. at com.sun.enterprise.web.connector.grizzly.DefaultProcessorTask.invokeAdapter(DefaultProcessorTask.java:647)
  51. at com.sun.enterprise.web.connector.grizzly.DefaultProcessorTask.doProcess(DefaultProcessorTask.java:579)
  52. at com.sun.enterprise.web.connector.grizzly.DefaultProcessorTask.process(DefaultProcessorTask.java:831)
  53. at com.sun.enterprise.web.connector.grizzly.DefaultReadTask.executeProcessorTask(DefaultReadTask.java:341)
  54. at com.sun.enterprise.web.connector.grizzly.DefaultReadTask.doTask(DefaultReadTask.java:263)
  55. at com.sun.enterprise.web.connector.grizzly.DefaultReadTask.doTask(DefaultReadTask.java:214)
  56. at com.sun.enterprise.web.portunif.PortUnificationPipeline$PUTask.doTask(PortUnificationPipeline.java:380)
  57. at com.sun.enterprise.web.connector.grizzly.TaskBase.run(TaskBase.java:265)
  58. at com.sun.enterprise.web.connector.grizzly.ssl.SSLWorkerThread.run(SSLWorkerThread.java:106)
  59.  

Code description:LoginServlet.java (Note doPost() dbOk=true)

JSP Syntax (Toggle Plain Text)
  1. package servlets;
  2. import java.io.IOException;
  3. import java.sql.SQLException;
  4. import java.util.ArrayList;
  5. import java.util.logging.Level;
  6. import java.util.logging.Logger;
  7. import javax.servlet.RequestDispatcher;
  8. import javax.servlet.ServletConfig;
  9. import javax.servlet.ServletException;
  10. import javax.servlet.http.HttpServletRequest;
  11. import javax.servlet.http.HttpServletResponse;
  12. import javax.servlet.http.HttpSession;
  13. import javax.servlet.http.HttpServlet;
  14.  
  15. import beans.UserBean;
  16. import model.DataManager;
  17. import model.Validation;
  18.  
  19.  
  20. public class LoginServlet extends HttpServlet
  21. {
  22.  
  23. private String dbResult = null;
  24. private String myException = null;
  25. private String strError = null;
  26. private boolean dbOK = false;
  27.  
  28. // Connection string data
  29. private String dbURL;
  30. private String dbusername;
  31. private String dbpassword;
  32.  
  33. //Instance of beans
  34. private UserBean userBean;
  35. private ArrayList<UserBean> students;
  36. private ArrayList<UserBean> teachers;
  37. private DataManager dataManager;
  38. private Validation val = new Validation();
  39.  
  40. public void LoginServlet(){
  41. System.out.println("in loginServlet");
  42. }
  43. public void init(ServletConfig config) throws ServletException
  44. {
  45. super.init(config);
  46.  
  47. dataManager = new DataManager();
  48. dataManager.setDbURL(config.getInitParameter("dbURL"));
  49. dataManager.setDbUserName(config.getInitParameter("dbUserName"));
  50. dataManager.setDbPassword(config.getInitParameter("dbPassword"));
  51. try
  52. {
  53. Class.forName(config.getInitParameter("jdbcDriver"));
  54. System.out.println("LoginServlet Init()<------------>Class.forName(config.getInitParameter('jdbcDriver')).toString<------------>Initialized the connector String");
  55. }
  56. catch (Exception ex)
  57. {
  58. System.out.println("Initialize connector string");
  59. ex.printStackTrace();
  60. }
  61. }
  62.  
  63. public void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException
  64. {
  65. /*
  66. * Get user data from submited form
  67. */
  68. String userName = request.getParameter("userName");
  69. String password = request.getParameter("password");
  70.  
  71. if(val.validate(userName, password))
  72. {
  73. System.out.println("LoginServlet Init()<------------>created a new UserBean object<------------>");
  74. userBean = new UserBean();
  75. try {
  76. userBean = dataManager.getUserData(userName, password);
  77. System.out.println("dataManager.getUserData()-------------->%"+userName+"%<--------------getParameter(userName)");
  78. System.out.println("dataManager.getUserData()-------------->%"+password+"%<--------------getParameter(passsword)");
  79. } catch (SQLException ex) {
  80. Logger.getLogger(LoginServlet.class.getName()).log(Level.SEVERE, null, ex);
  81. }
  82.  
  83. try
  84. {
  85. if(!userBean.getUid().equals(null))
  86. dbOK = true;
  87. System.out.println("doPost()-------------->%"+dbOK+"%<--------------dbOk");
  88.  
  89. }
  90. catch(NullPointerException npe)
  91. {
  92. System.out.println("doPost()-------------->%%<--------------blows up here");
  93.  
  94. System.out.println("Error on DB return");
  95. npe.printStackTrace();
  96. strError = "Invalid username or password.";
  97. dbOK = false;
  98. }
  99.  
  100. }
  101. else
  102. {
  103. strError = "Invalid username or password.";
  104. dbOK = false;
  105. }
  106.  
  107. HttpSession session = request.getSession(true);
  108.  
  109. if(dbOK)
  110. {
  111. //redirect to student/teacher/admin pages
  112. if(userBean.getUserGroup().equals("student"))
  113. {
  114. session.setAttribute( "userBean", userBean);
  115. RequestDispatcher dispatcher = request.getRequestDispatcher("/student.jsp");
  116. dispatcher.forward( request, response);
  117. }
  118. else if(userBean.getUserGroup().equals("teacher"))
  119. {
  120. session.setAttribute( "userBean", userBean);
  121. students = new ArrayList<UserBean>(dataManager.getUsersList("student"));
  122. session.setAttribute("students", students);
  123. RequestDispatcher dispatcher = request.getRequestDispatcher("/teacher.jsp");
  124. dispatcher.forward( request, response);
  125. }
  126. else if(userBean.getUserGroup().equals("admin"))
  127. {
  128. session.setAttribute( "userBean", userBean);
  129. students = new ArrayList<UserBean>(dataManager.getUsersList("student"));
  130. session.setAttribute("students", students);
  131. teachers = new ArrayList<UserBean>(dataManager.getUsersList("teacher"));
  132. session.setAttribute("teachers", teachers);
  133. RequestDispatcher dispatcher = request.getRequestDispatcher("/admin.jsp");
  134. dispatcher.forward( request, response);
  135. }
  136. }
  137. else
  138. {
  139. //Error after DB login checkout, redirect back to index.jsp
  140. session.setAttribute( "error", strError);
  141. RequestDispatcher dispatcher = request.getRequestDispatcher("/index.jsp");
  142. dispatcher.forward( request, response);
  143. }
  144. }
  145. }



Thanks again.
-ceyesuma


Note:

I plan on re-write in order to try prepared stmt and tag library.
so this error may or may not repeat itself.
Last edited by ceyesuma; Sep 18th, 2009 at 11:24 am. Reason: additional note
Reputation Points: 7
Solved Threads: 2
Posting Pro
ceyesuma is offline Offline
524 posts
since Aug 2007
Sep 18th, 2009
0

Re: JSP database connectivity

Hello again.
I have re-written all the previous posted code using the preparedStatement().
good stuff.

Now, When I started I chose to use JSF1.2. I think my error at described above is because there are no navigation rules (go figure lol you think that is the cause for the error?)

So, my questionsare:
1. can I leave the web.xml along now? (that is where my connecting param's are)
2. can I create the navigation rules in the face-config.xml?
3.finally, Is it possible to rewrite the pages supplied using JSF JSP jsp pages?
Thanks again
ceyesuma
Reputation Points: 7
Solved Threads: 2
Posting Pro
ceyesuma is offline Offline
524 posts
since Aug 2007
Sep 19th, 2009
-1

Re: JSP database connectivity

You will always need web.xml for few things. If face-config.xml support navigation rules you may try to rewrite it, but unfortunately I cannot be of any assistance because I did not use JSF as yet.
If you succeed please post it on forum for others to see it.
Moderator
Featured Poster
Reputation Points: 2786
Solved Threads: 871
Code tags enforcer
peter_budo is offline Offline
6,655 posts
since Dec 2004
Sep 19th, 2009
0

Re: JSP database connectivity

Hello.
I worked all night on a couple other projects but I believe the Netbeans project is still at:
http://cid-b5cb457363230793.skydrive...lic/school.zip
I think that one is still not using preparedStatements though.

I will work on it soon. However if some one where to open it in netbeans I believe it would just be a matter of adding a dataManagerController.java that the jsf jsp page talks to and the controler talks to the model DataManager.java dataManager.isStudent()which has the method that would return the string "student","admin" etc to the
faces-conf.xml which has the case and navigation for the pages.



a good simple calulator example is at
http://www.ibm.com/developerworks/li...j-jsf1/#N100D3

I cant upload a worksheet.xls (excel) I have a summary of that tutorial named simpljsf.zip at:
http://cid-b5cb457363230793.skydrive.../simplejsf.zip


thanks
-ceyesumma
Reputation Points: 7
Solved Threads: 2
Posting Pro
ceyesuma is offline Offline
524 posts
since Aug 2007

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in JSP Forum Timeline: printed in server instead of client
Next Thread in JSP Forum Timeline: data retrieval trouble





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC