insert new values in table using servlet ??

Posted on 2002-05-07
Medium Priority
Last Modified: 2013-11-24
would u give me simple example how to store values which are send from a form to a servlet into tables in microsoft access.
Question by:star4
LVL 18

Accepted Solution

bobbit31 earned 200 total points
ID: 6994916
import java.sql.*;

Connection con = null;

try {

   con = DriverManager.getConnection("jdbc:odbc:<DSN>");

   Statement stmt = con.createStatement();
   stmt.executeUpdate("Insert into <your table> (field1, field2, field3) values (<param1>, <param2>, <param3>)");
} catch (Exception e) {
} finally {
   if (con != null) { con.close(); }

to get parameters from form:

String param1 = request.getParameter("param1");
String param2 = request.getParameter("param2");
String param3 = request.getParameter("param3");


Author Comment

ID: 7022252
may u help again bobbit31 :
i tried this code but nothing is entered in the database ?

 String strSQL,strSQL1,strSQL2;
               String empno,password,todaydate,massage;
               //Storing the result of Query in those variavles
               //after initializing them to null
               ResultSet rs=null, rs1=null;
            Statement stmt;
               //Making variables and initialze them
               int i=0;
               //In order to establish a connection to the databse
               //we should have the approperiate driver connect to
               //the DBMS.
               //db1 : is the name of the database where it is defind
               //on the jdbc:odbc driver
               Class.forName ("sun.jdbc.odbc.JdbcOdbcDriver");
           con = DriverManager.getConnection("jdbc:odbc:db1");
                                                                //Creating statement for connection
               stmt = con.createStatement();
               //Get userid ,password ,month and year from the
               //web site forms, and store them in the approperiate variables
               empno = req.getParameter("empid");
            password = req.getParameter("password");
               todaydate = req.getParameter("todaydate");
            massage = req.getParameter("massage");
               //Check the Empid and password intered by the user
               //match the Empid and password stored in table LoginTable
               strSQL = "select * from LoginTable " +
            "where EmpID like '" + empno + "' and " +
           "Password like '" + password + "'";
              rs = stmt.executeQuery(strSQL);
               //If password and Empid are correct then assign true to logged
               //otherwise assign false
               if (rs.next())                                                      
                     //Password and Empid are correct
                     //close the result
                  //Password or Empid are not correct
                     logged =false;
               //IF logged = true
                if (logged)
            stmt.executeUpdate("Insert into reqleaves (empno,sendeddate,massage)values (empno, todaydate,massege)");
              out.println("Please Check your id and password");
                  //close the statement
              //if errors exist then display them
       } catch (Exception e)
            if (con != null)
                 } catch (SQLException se) {

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Are you developing a Java application and want to create Excel Spreadsheets? You have come to the right place, this article will describe how you can create Excel Spreadsheets from a Java Application. For the purposes of this article, I will be u…
Java functions are among the best things for programmers to work with as Java sites can be very easy to read and prepare. Java especially simplifies many processes in the coding industry as it helps integrate many forms of technology and different d…
Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …
How to fix incompatible JVM issue while installing Eclipse While installing Eclipse in windows, got one error like above and unable to proceed with the installation. This video describes how to successfully install Eclipse. How to solve incompa…
Suggested Courses

600 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question