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(AuthR el 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_SCROL L_SENSITIV E,ResultSe t.CONCUR_R EAD_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("update Author_Pho ne_T()-ssn = "
+ ar.getSsn());
ps.setString(4, ar.getAuth_start_dt());
System.out.println("update Author_Pho ne_T()-Aut h_start_dt = "
+ ar.getAuth_start_dt());
ps.setString(5, phone_purpcd);
System.out.println("update Author_Pho ne_T()-pho ne_purpcd = "
+ phone_purpcd);
rowCount = ps.executeUpdate();
if (rowCount > 0){
ar.setActionToPerform(Auth orizationR elease.UPD ATE);
} else {
ar.setActionToPerform(Auth orizationR elease.INS ERT);
}
}
} 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;
}
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(AuthR
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,
//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("update
+ ar.getSsn());
ps.setString(4, ar.getAuth_start_dt());
System.out.println("update
+ ar.getAuth_start_dt());
ps.setString(5, phone_purpcd);
System.out.println("update
+ phone_purpcd);
rowCount = ps.executeUpdate();
if (rowCount > 0){
ar.setActionToPerform(Auth
} else {
ar.setActionToPerform(Auth
}
}
} 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;
}
"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)
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?
ASKER
The jdbc driver supports an insert and a delete.
"update dss.author_phone_t " + ? does not work either
"update dss.author_phone_t " + ? does not work either
What is the error you're getting ?!
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
What errors do you get and can you post your stackTrace() from your console?
David