473,289 Members | 2,155 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,289 software developers and data experts.

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

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

Similar topics

0
by: Sofia | last post by:
My name is Sofia and I have for many years been running a personals site, together with my partner, on a non-profit basis. The site is currently not running due to us emigrating, but during its...
0
by: Gregory Nans | last post by:
hello, i need some help to 'tree-ify' a string... for example i have strings such as : s = """A(here 's , B(A ) silly test) C(to show D(what kind) of stuff i need))""" and i need to...
0
by: xunling | last post by:
i have a question about answering ..... this topic is "need help" what do i have to write at te topic line, !after i have klicked the "answer message" button ive tried many possibilities,...
11
by: blah | last post by:
Need python Pro at newtopython@googlegroups.com , if u wanna help, plz reply to that address. We are python beginners. need a real good Python Programmer for Help. TIA!! -- * Posted with...
4
by: Scott Holland | last post by:
HELP - Need to connect to DB2 database on AIX from NT server. Also AS/400 from NT Server -- I am experienced in ORACLE and a novice at DB2. What tools would be the equivalent of Net*8 or...
2
by: Paul Mendez | last post by:
I really need some help Date Code ConCAT Bal_Fwd NS_Fees Amt_Coll Cur_End_Bal 1/15/2004 KW 11KW2003 $500.00 $250.00 $250.00 2/15/2004 KW 12KW2003 $300.00 $500.00 ...
1
by: MSDN Account | last post by:
We have web site that used the IIS ResKit tool MSWC.PermissionChecker to check file permissions. The web site has been upgraded and that upgrade included changing the default server side language...
8
by: Elliot M. Rodriguez | last post by:
I am having a heckuva time debugging this, or determining why my page is behaving this way. I have a search form, that when completed, returns a datagrid. When the user selects a row (normal...
23
by: vinod.bhavnani | last post by:
Hello all, I need desperate help Here is the problem: My problem today is with multidimensional arrays. Lets say i have an array A this is a 4 dimensional static array.
2
by: XML Beginner | last post by:
I have an XML file that contains values that my application needs, so it knows which database to connect to. It also contains a configuration option so that I can specify which node to return...
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 7 Feb 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:30 (7.30PM). In this month's session, the creator of the excellent VBE...
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
by: Aftab Ahmad | last post by:
Hello Experts! I have written a code in MS Access for a cmd called "WhatsApp Message" to open WhatsApp using that very code but the problem is that it gives a popup message everytime I clicked on...
0
by: Aftab Ahmad | last post by:
So, I have written a code for a cmd called "Send WhatsApp Message" to open and send WhatsApp messaage. The code is given below. Dim IE As Object Set IE =...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: marcoviolo | last post by:
Dear all, I would like to implement on my worksheet an vlookup dynamic , that consider a change of pivot excel via win32com, from an external excel (without open it) and save the new file into a...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.