Results 1 to 5 of 5
  1. #1
    Join Date
    May 2007
    Posts
    5

    Unanswered: executeUpdate not executed

    Hi,
    I m using mysql and Jboss 4.0.4 GA. I m trying to insert the data in the database. but executeUpdate command is not executed. It doesn't shhows anything in the log file.it prints the values in the server's log but not executing this command (I mean not showing values in database)and doesn't shows any error in the
    Please help me

    Thanks

  2. #2
    Join Date
    Nov 2003
    Posts
    2,933
    Provided Answers: 12
    Did you commit your changes?
    Are you catching and processing any Exceptions that might be thrown by executeUpdate()

  3. #3
    Join Date
    May 2007
    Posts
    5
    it doesn't show any exception. I send u the code that i m using. it doesn't show any error in the log but not displaying data in the database


    package com.pdws.action;
    import java.io.IOException;
    import java.sql.Connection;
    import java.sql.PreparedStatement;
    import java.sql.ResultSet;
    import java.sql.Statement;
    import javax.servlet.http.HttpServletRequest;
    import javax.servlet.http.HttpServletResponse;
    import org.apache.struts.action.Action;
    import org.apache.struts.action.ActionMapping;
    import org.apache.struts.action.ActionForm;
    import org.apache.struts.action.ActionForward;
    import java.util.ArrayList;
    import javax.sql.DataSource;
    import com.pdws.vo.*;
    import javax.servlet.http.HttpSession;

    public class DepartmentAction extends Action{
    public ActionForward execute(ActionMapping mapping,ActionForm form,HttpServletRequest request,HttpServletResponse response) throws Exception{
    //DbConnect dbobj=new DbConnect();
    DataSource ds = this.getDataSource(request);
    DepartmentVO deptvo=new DepartmentVO();
    HttpSession session=request.getSession(true);
    String dcode=request.getParameter("dCode");
    System.out.println(dcode);
    String dname=request.getParameter("dName");
    System.out.println(dname);
    boolean flag = false;
    deptvo.setDeptcode(dcode);
    deptvo.setDeptname(dname);
    flag = addInfo(dcode,dname, ds);

    return mapping.findForward("show");
    }
    public boolean addInfo(String dcode, String dname, DataSource ds) throws Exception {
    Connection con = null;
    Statement stmt_get = null;
    Statement stmt_set = null;
    PreparedStatement psmt = null;
    ResultSet rs = null;
    try {
    con = ds.getConnection();
    stmt_get = con.createStatement();
    stmt_set = con.createStatement();
    System.out.println("database connected 1");
    String sqString = null;
    try {
    psmt = con.prepareStatement("insert into dept values(?,?)");
    psmt.setString(1, dcode);
    psmt.setString(2, dname);
    System.out.println(dcode);
    System.out.println("database connected 2");
    psmt.executeUpdate();
    System.out.println("database connected 3");
    } catch (Exception e) {
    System.out.println("Error in sql command 4");
    }
    } catch (Exception uaexist) {
    uaexist.printStackTrace();
    } finally {
    if (rs != null)
    rs.close();
    if (stmt_get != null)
    stmt_get.close();
    if (stmt_set != null)
    stmt_set.close();
    if (con != null)
    con.close();
    System.out.println("database connected 5");
    }
    return true;

    }
    }


    Thanks for ur reply

  4. #4
    Join Date
    Nov 2003
    Posts
    2,933
    Provided Answers: 12
    Read my first question: where is your commit?
    (and you should use code tags the next time you post code)

  5. #5
    Join Date
    Jun 2007
    Posts
    2
    Easiest solution, but manual commits are probably better.


    PreparedStatement psmt = null;
    ResultSet rs = null;
    try {
    con = ds.getConnection();

    con.setAutoCommit(true);

    stmt_get = con.createStatement();
    stmt_set = con.createStatement();

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •