insertion of values through jsp into database

DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Results 1 to 2 of 2

Thread: insertion of values through jsp into database

  1. #1
    Join Date
    Nov 2004

    insertion of values through jsp into database

    i want a query which i have to be used in jsp page, that the values of html page, which display in jsp page get stored in oracle coonnection is working, but the value is not stored in database.

    the values is get from the html page, by using request.getParameter("code") method.

    i have used the following query, but it is not working:

    <%@ page import="javax.servlet.*" %>
    <%@ page import="javax.servlet.http.*" %>

    <%@ page language="java" import="java.sql.*" %>



    try {
    //Load the jdbc driver


    //Create a connection object

    Connection con=DriverManager.getConnection("jdbcdbcf","scott","ttlscott");

    System.out.println("got connection");

    // Create a statement object and call its executeUpdate method to insert a record

    Statement s=con.createStatement();

    String sql = "insert into gl_mast values(\"" + request.getParameter("code") + "\",\"" + request.getParameter("Description") + "\",\"" + request.getParameter("DrAmount") + "\",\"" + request.getParameter("CrAmount") + "\",\"" + request.getParameter("type") + "\",\"" + request.getParameter("pct") + "\"")";


    Step 4. Use the same Statement object to obtain a ResultSet object

    ResultSet rs = s.executeQuery(sql);

    catch (ClassNotFoundException e1) {
    // JDBC driver class not found, print error message to the console
    catch (SQLException e2) {
    // Exception when executing java.sql related commands, print error message to the console
    catch (Exception e3) {
    // other unexpected exception, print error message to the console

  2. #2
    Join Date
    Oct 2004
    It is possible that your database is setup with autoCommit disabled. This is goodpracticve since it means you have transaction based database access. What you need to do in such a case is use con.commit(); before closing the connection to the database.

    Also, you might want to rearrange your code a bit, because you need to close you connection in case f an exception as well. This means you need to define it before entering the try{} block. (Connection = null That way, you can assign it in your try block, and close it in your catch(){} blocks.

    Also, before you close the connection in your catch(){} block, you should call the con.rollback(); method. this undo's all the changes you made to the database (insert / update / delete / etc.)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
HTML5 Development Center
Latest Articles
Questions? Contact us.
Web Development
Latest Tips
Open Source

   Development Centers

   -- Android Development Center
   -- Cloud Development Project Center
   -- HTML5 Development Center
   -- Windows Mobile Development Center