Link to home
Start Free TrialLog in
Avatar of coolgem
coolgem

asked on

JAVA:rowCount = ps.executeUpdate();

Hi, I'm getting an error on the execute update(). Are the statements ok?
Thank you for your time. coolgem
The table has four fields: in this order: ssn, phone_purpcd, phone_nr,auth_start_dt

the code is:
public int updateAuthor_Phone_T(AuthRel ar, String phone_purpcd) throws SQLException, NamingException{
            Connection conn = null;
            PreparedStatement ps = null;
            int rowCount = 0;
            try {
                  if (ar.getSsn() != "" && ar.getAuth_start_dt() != "") {
                        conn = dataSource.getConnection();
                        String sql =
                              "update dss.author_phone_t aut " +
                              "set " +
                              "aut.phone_nr = ? " +
                              "where (aut.ssn = ? and  aut.auth_start_dt = "+this.toDate("?",DBO.DATE)+
                              "and aut.phone_purpcd = ?)";                         
            
                        ps =
                        conn.prepareStatement(sql,ResultSet.TYPE_SCROLL_SENSITIVE,ResultSet.CONCUR_READ_ONLY);
                        //D is duty number F is fax                                                                                                   + phone_purpcd);
                        if (phone_purpcd == "D"){
                              ps.setString(1, ar.getOrg_phone_nr());      
                        } else if (phone_purpcd == "F") {
                              ps.setString(1, ar.getOrg_fax_nr());
                        }
                        ps.setString(2, ar.getSsn());
                        System.out.println("updateAuthor_Phone_T()-ssn = "
                                           + ar.getSsn());
                        ps.setString(4, ar.getAuth_start_dt());
                        System.out.println("updateAuthor_Phone_T()-Auth_start_dt = "
                                                                           + ar.getAuth_start_dt());
                        ps.setString(5, phone_purpcd);
                        System.out.println("updateAuthor_Phone_T()-phone_purpcd = "
                                                                                                   + phone_purpcd);                                          
                        rowCount = ps.executeUpdate();
                        if (rowCount > 0){
                              ar.setActionToPerform(AuthorizationRelease.UPDATE);            
                        } else {
                              ar.setActionToPerform(AuthorizationRelease.INSERT);
                        }                  
                  }
            } catch (SQLException x) {
                  rowCount = 0;
                  ModelUtils.log(x);
            } catch (Exception x) {
                  ModelUtils.log(x);
            } finally {
                  try {
                        close(conn, ps);
                  } catch (SQLException x) {
                        ModelUtils.log(x);
                  }
            }
            return rowCount;
      }      
Avatar of suprapto45
suprapto45
Flag of Singapore image

Hi,

What errors do you get and can you post your stackTrace() from your console?

David
"update dss.author_phone_t aut " +

Should that not be

"update dss.author_phone_t " +

?

(Or, if 'aut' is a table name, then seperate using a comma)
Avatar of liviutudor
liviutudor

Have you tried calling simply execute() instead of executeUpdate()? Perhaps your JDBC driver does not support it? What database/driver are you using?
Avatar of coolgem

ASKER

The jdbc driver supports an insert and a delete.  

"update dss.author_phone_t " + ? does not work either

What is the error you're getting ?!
ASKER CERTIFIED SOLUTION
Avatar of int_20h
int_20h

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial