473,320 Members | 1,939 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,320 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 3295
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...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
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...
1
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: 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: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

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.