We help IT Professionals succeed at work.

JAVA:rowCount = ps.executeUpdate();

coolgem
coolgem asked
on
Medium Priority
1,429 Views
Last Modified: 2008-03-10
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;
      }      
Comment
Watch Question

Hi,

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

David
Top Expert 2006

Commented:
"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)
Have you tried calling simply execute() instead of executeUpdate()? Perhaps your JDBC driver does not support it? What database/driver are you using?

Author

Commented:
The jdbc driver supports an insert and a delete.  

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

Top Expert 2006

Commented:
What is the error you're getting ?!
Commented:
Without the stack trace or the exception we will be guessing so, here is my guess:

                         "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 = ?)";    

I see 4 "?"... Yet you have:
ps.setString(1, ar.getOrg_phone_nr());    
ps.setString(2, ar.getSsn());
ps.setString(4, ar.getAuth_start_dt());
ps.setString(5, phone_purpcd);

Where is "3"??? I think your "4" is "3" and your "5" is "4".  So, where is an updated query:

                         "update dss.author_phone_t aut " +
                         "set " +
                         "aut.phone_nr = ? " +
                         "where (aut.ssn = ? and  aut.auth_start_dt = ? " +
                         "and aut.phone_purpcd = ?)";    
ps.setString(1, ar.getOrg_phone_nr());    
ps.setString(2, ar.getSsn());
ps.setDate(3, converToDate(ar.getAuth_start_dt()));
ps.setString(4, phone_purpcd);

You need a way to convert it to date in Java or use the Date convertion from you DB...directly in the sql statement...

Not the solution you were looking for? Getting a personalized solution is easy.

Ask the Experts
Access more of Experts Exchange with a free account
Thanks for using Experts Exchange.

Create a free account to continue.

Limited access with a free account allows you to:

  • View three pieces of content (articles, solutions, posts, and videos)
  • Ask the experts questions (counted toward content limit)
  • Customize your dashboard and profile

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

OR

Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.