469,573 Members | 1,660 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,573 developers. It's quick & easy.

Need Help-How to insert input parameter in DB through Java Bean

Hello Sir,
I have a simple Issue but It is not resolve by me i.e input parameter
are not store in Ms-Access.
I store the input parameter through Standard Action <jsp:useBean>.
jsp:useBean call a property IssueData. this property exist in
SimpleBean which create a connection from DB and insert the data.

At run time servlet and server also show that loggging are saved in DB.
But when I open the table in Access. Its empty.
Ms-Access have two fields- User, Password both are text type.
Please review these code:
login.html:

Expand|Select|Wrap|Line Numbers
  1. <html>
  2. <head>
  3. <title>A simple JSP application</title>
  4. <head>
  5. <body>
  6. <form method="get" action="tmp" >
  7. Name: <input type="text" name="user">
  8. Password: <input type="password" name="pass">
  9. <input type="Submit" value="Submit">
  10. </form>
  11. </body>
  12. </html>
LoginServlet.java:

Expand|Select|Wrap|Line Numbers
  1. import javax.servlet.*;
  2. import javax.servlet.http.*;
  3. public class LoginServlet extends HttpServlet{
  4. public void doGet(HttpServletRequest request, HttpServletResponse response)
  5. throws ServletException{
  6. try
  7. {
  8. String user=request.getParameter("user");
  9. String pass=request.getParameter("pass");
  10.  
  11. co.SimpleBean st = new co.SimpleBean();
  12.  
  13. st.setUserName(user);
  14. st.setPassword(pass);
  15.  
  16.  
  17. request.setAttribute("user",st);
  18. request.setAttribute("pass",st);
  19. RequestDispatcher dispatcher1 =request.getRequestDispatcher("submit.jsp");
  20. dispatcher1.forward(request,response);
  21. }
  22. catch(Exception e)
  23. {
  24. e.printStackTrace();
  25. }
  26. }
  27. }
SimpleBean.java:

Expand|Select|Wrap|Line Numbers
  1. package co;
  2. import java.util.*;
  3. import java.io.*;
  4. import javax.servlet.*;
  5. import javax.servlet.http.*;
  6. import java.sql.*;
  7. import java.util.*;
  8.  
  9. public class SimpleBean {
  10.  
  11. private String user="";
  12. private String pass="";
  13. private String s="";
  14.  
  15. public String getUserName() {
  16. return user;
  17. }
  18. public void setUserName(String user) {
  19. this.user = user;
  20. }
  21. public String getPassword() {
  22. return pass;
  23. }
  24. public void setPassword(String pass) {
  25. this.pass = pass;
  26. }
  27.  
  28. public String getIssueData() //method that create connection with database
  29. {
  30. try
  31. {
  32. System.out.println("Printed*************************************************************");
  33. getUserName();
  34. getPassword();
  35.  
  36. Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
  37. System.out.println("Loading....");
  38. Connection con=DriverManager.getConnection("jdbc:odbc:simple");
  39. System.out.println("Connected....");
  40. PreparedStatement st=con.prepareStatement("insert into Table1 values(?,?)");
  41. System.out.println("~~~~~~~~~~~~~~~~~~~~");
  42. String User=getUserName();
  43. st.setString(1,User);
  44. String Password=getPassword();
  45. st.setString(2,Password);
  46.  st.executeUpdate();
  47. System.out.println("Query Executed");
  48.  con.close();
  49.  s=  "Your logging is saved in DB ";
  50. System.out.println("Your logging is saved in DB *****************");
  51. return(s);
  52. }
  53. catch(Exception e)
  54. {
  55. e.printStackTrace();
  56. return "failed";
  57. }
  58. }
  59. }
  60.  
submit.jsp:
This is Submit page

Expand|Select|Wrap|Line Numbers
  1. <html><body>
  2. Hello
  3. Student Name: <%= ((co.SimpleBean)request.getAttribute("user")).getUserName() %>
  4. <br>
  5. Password: <%= ((co.SimpleBean)request.getAttribute("pass")).getPassword() %>
  6. <br>
  7. <jsp:useBean id="st" class="co.SimpleBean" scope="request" />
  8. <jsp:getProperty name="st" property="IssueData" />
  9. </body></html>
web.xml:

Expand|Select|Wrap|Line Numbers
  1. <web-app>
  2.  
  3. <servlet>
  4. <servlet-name>one</servlet-name>
  5. <servlet-class>LoginServlet</servlet-class>
  6. </servlet>
  7.  
  8. <servlet-mapping>
  9. <servlet-name>one</servlet-name>
  10. <url-pattern>/tmp</url-pattern>
  11. </servlet-mapping>
  12.  
  13. <jsp-file>issue.jsp</jsp-file>
  14. <jsp-file>submit.jsp</jsp-file>
  15. <url-pattern>*.do</url-pattern>
  16.  
  17. <welcome-file-list>
  18. <welcome-file>Login.html</welcome-file>
  19. </welcome-file-list>
  20.  
  21. </web-app>


Please Help me..Thanks.!!!
--
Oct 18 '08 #1
2 3037
pronerd
392 Expert 256MB
It does not look like you are calling the getIssueData() method any where. Since that is where the code is that writes the data to the database if you do not call it the data will never be written.
Oct 20 '08 #2
It does not look like you are calling the getIssueData() method any where. Since that is where the code is that writes the data to the database if you do not call it the data will never be written.
Dear Sir,
Can you write me How that code will be invoke which write in getIssueData().
Please Help me...
Oct 21 '08 #3

Post your reply

Sign in to post your reply or Sign up for a free account.

Similar topics

reply views Thread by Sofia | last post: by
reply views Thread by Gregory Nans | last post: by
reply views Thread by xunling | last post: by
11 posts views Thread by blah | last post: by
1 post views Thread by MSDN Account | last post: by
8 posts views Thread by Elliot M. Rodriguez | last post: by
23 posts views Thread by vinod.bhavnani | last post: by
2 posts views Thread by XML Beginner | last post: by
reply views Thread by suresh191 | last post: by
4 posts views Thread by guiromero | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.