Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 1007459
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T08:37:17+00:00 2026-05-16T08:37:17+00:00

response.setContentType(text/html); PrintWriter out = response.getWriter(); Connection conn = null; String url = jdbc:mysql://localhost:3306/; String

  • 0
  response.setContentType("text/html");
  PrintWriter out = response.getWriter();
  Connection conn = null;
  String url = "jdbc:mysql://localhost:3306/";
  String dbName = "Employee";
  String driver = "com.mysql.jdbc.Driver";
  String userName = "root"; 
  String password = "1234";

  int Empid =Integer.parseInt(request.getParameter("Empid").toString()); 
  String Name = request.getParameter("Name").toString();
  int Age =Integer.parseInt(request.getParameter("Age").toString()); 
  int Salary =Integer.parseInt(request.getParameter("Salary").toString());
  Statement stmt;
  try {
   Class.forName(driver).newInstance();
   conn = DriverManager.getConnection(url+dbName,userName,password);
   System.out.println("Connected to the database");

   ArrayList al=null;
   ArrayList userList =new ArrayList();
   String query = "insert into employee set Empid='"+Empid+"',name='"+Name+"',Age='"+Age+"',Salary='"+Salary+"'";
   stmt = conn.createStatement();

      int i = stmt.executeUpdate(query);
   System.out.println("query" + query);
   if(i>0)
   {
    response.sendRedirect("servletRecord");
   }
   conn.close();
   System.out.println("Disconnected from database");
  } catch (Exception e) {
  e.printStackTrace();

I want to get the values and add it in a database using this program, but I don’t know what error there is. What should I do next to create a corresponding webpage to enter the values and add it to the table?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-16T08:37:17+00:00Added an answer on May 16, 2026 at 8:37 am

    That’ll be HTML. First learn HTML, especially HTML forms.

    You want to use a HTML form. Create a JSP file which should serve this HTML to the webbrowser. It’ll look something like:

    <!DOCTYPE html>
    <html lang="en">
        <head><title>Hello World</title></head>
        <body>
            <form action="servleturl" method="post">
                <p>Empid: <input name="Empid">
                <p>Name: <input name="Name">
                <p>Age: <input name="Age">
                <p>Salary: <input name="Salary">
                <p><input type="submit">
            </form>
        </body>
    </html>
    

    You only need to change the form action value to match the <url-pattern> of the servlet as mapped in the web.xml.

    See also:

    • Basic JSP/Servlet tutorials
    • Java web development, what skills do I need?

    That said and unrelated to the actual question, your JDBC code is sensitive to SQL injection attacks. Use PreparedStatement all the way. Prepare here. Then I don’t talk about the connection leak risks yet.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 507k
  • Answers 507k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer If you want to avoid calling eval you can also… May 16, 2026 at 3:55 pm
  • Editorial Team
    Editorial Team added an answer something like this should do the trick, although this example… May 16, 2026 at 3:55 pm
  • Editorial Team
    Editorial Team added an answer the second parameterf is the number of frames per second… May 16, 2026 at 3:55 pm

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Related Questions

I can use: return new ModelAndView(viewName, model); Or I use: response.setContentType(text/plain); response.getWriter().print(Hello World!); Now
I have to do an HTML page with 2 text boxes, one for name
I have the following servlet code public void doPost(HttpServletRequest request, HttpServletResponse response){ Backup bup
When trying to pass a table built with HTML in my servlet like that:
Greetings! I'm having a problem getting a text value of a captcha from a
I want to ask how to open a specific file (the file is out
Ajax response I am getting is always empty! Interestingly, if I copy paste that
This is the response I'll be getting: <?xml version=1.0 encoding=utf-8?> <rsp stat=ok> <image_hash>cxmHM</image_hash> <delete_hash>NNy6VNpiAA</delete_hash>
From a response to some question yesterday, I learned that it is nonportable and
I have a soap response which is RPC style, so it has 'multiref's. The

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.