Results 1 to 2 of 2
  1. #1
    Join Date
    Mar 2003
    Location
    SJ, Costa Rica
    Posts
    48

    Unanswered: updates don't working

    Hi everybody, I'm having problems trying to update a database table.
    I have a class that implement the following method:

    Code:
    public void updTable(String pSqlString)
            {
                try{
                    Class.forName("com.mysql.jdbc.Driver").newInstance();
                   this.cn=DriverManager.getConnection("jdbc:mysql://"        +this.servidor+ ":3306" + 
    "/holdingsdb?user=" +this.getUsuario()+ "&" +
                   "password=" +this.getClave()+ "");
                    this.st=this.cn.createStatement();
                    this.st.executeUpdate(pSqlString);
                    this.cn.commit();
                    this.st.close();
                    this.cn.close();
                }catch(Exception e){System.err.println("Error al hacer el             update");                
              }
            }
    I'm using mysql J-Connector driver, but everytime I want to make an update to one table I get a Java Exception that begins with the following line:

    Code:
    org.apache.jasper.JasperException: net.numar.holdings.Conn.updTable(Ljava/lang/String;)V

    I have another method that is exactly to the above one with the exception that instead of the line:
    Code:
                    this.st.executeUpdate(pSqlString);
    I have this other line:
    Code:
                    Resultset rs=this.st.executeQuery(pSqlString);
    The funny is that this last method works fine for selects, but not for updates or inserts, so that's why I'm using the method I've posted.
    thanks in advance for any advice...
    regards,
    -eduardo s.m.

  2. #2
    Join Date
    Jan 2004
    Posts
    11
    executeQuery() always works only for selects.
    For inserts, we have to use executeUpdate().
    Try using a generic method execute(), though I very much doubt whether it will help.
    Sorry for not being of any help..

Posting Permissions

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