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;
      }      
coolgemAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

suprapto45Commented:
Hi,

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

David
0
InteractiveMindCommented:
"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)
0
liviutudorCommented:
Have you tried calling simply execute() instead of executeUpdate()? Perhaps your JDBC driver does not support it? What database/driver are you using?
0
Ultimate Tool Kit for Technology Solution Provider

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy now.

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

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

0
InteractiveMindCommented:
What is the error you're getting ?!
0
int_20hCommented:
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...
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Programming

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.