Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
?
Solved

JAVA:rowCount = ps.executeUpdate();

Posted on 2006-03-20
6
Medium Priority
?
1,338 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;
      }      
0
Comment
Question by:coolgem
6 Comments
 
LVL 16

Expert Comment

by:suprapto45
ID: 16242931
Hi,

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

David
0
 
LVL 25

Expert Comment

by:InteractiveMind
ID: 16246272
"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
 
LVL 6

Expert Comment

by:liviutudor
ID: 16246396
Have you tried calling simply execute() instead of executeUpdate()? Perhaps your JDBC driver does not support it? What database/driver are you using?
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Author Comment

by:coolgem
ID: 16249580
The jdbc driver supports an insert and a delete.  

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

0
 
LVL 25

Expert Comment

by:InteractiveMind
ID: 16249592
What is the error you're getting ?!
0
 
LVL 3

Accepted Solution

by:
int_20h earned 2000 total points
ID: 16250398
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

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Although it can be difficult to imagine, someday your child will have a career of his or her own. He or she will likely start a family, buy a home and start having their own children. So, while being a kid is still extremely important, it’s also …
The SignAloud Glove is capable of translating American Sign Language signs into text and audio.
In this fifth video of the Xpdf series, we discuss and demonstrate the PDFdetach utility, which is able to list and, more importantly, extract attachments that are embedded in PDF files. It does this via a command line interface, making it suitable …
Simple Linear Regression

581 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question