sqlcommand not properly ended

80 views Asked by At

i cannot update my form. it says that my sql is not properly ended. this is my updateCust of custDao. The ResultSet seem not be used. it seems to direct go to catch exception.

 public void updateCust(Customer cust) {
  try {
    Statement statement = con.createStatement();
    ResultSet rs = statement.executeQuery("UPDATE CUSTOMER "
            + "SET custName =        '" + cust.getCustName() + "',"
            + "custAdd = '" + cust.getCustAdd() + "',"
            + "custRegion = '" + cust.getCustRegion() + "' "
            + "custHandphoneNo = '" + cust.getCustHandphoneNo() + "' "
            + "custPhoneNo = '" + cust.getCustPhoneNo() + "' "
            + "custEmail = '" + cust.getCustEmail() + "' "
            + "WHERE cust_id = " + cust.getCust_id());
  } catch (SQLException e) {
    e.printStackTrace();
    System.out.println("problem update");
  }
}

this is my form after retrieve data from searchbox

<form action="CustomerController?action=edit" method="post">
    <table>
        <tr>
            <td style:width="30px"><h3 class="templatemo-gold">ID Number: </h3></td>
            <td style:width="70px">><input type="text" name="cust_id" id="cust_id" value="${custDetail.cust_id}"/> <br/><br/>
            </td>
        </tr>
        <tr>
            <td><h3 class="templatemo-gold">Name: </h3></td>
            <td><input type="text" name="custName" id="custName" size="50" value="${custDetail.custName}"/> <br/><br/>
            </td>
        </tr>

        <tr>
            <td><h3 class="templatemo-gold">Address: </h3></td>
            <td><input type="text" name="custAdd" size="50" value="${custDetail.custAdd}"
                    /><br/><br/></td>
        </tr>
        <tr>
            <td><h3 class="templatemo-gold">Region: </h3></td>
            <td><input type="text" name="custRegion" id="custRegion" size="50" value="${custDetail.custRegion}"
                    /><br/><br/></td>
        </tr>
        <tr>
            <td>
        <tr><h3 class="templatemo-gold">Handphone No: </h3></td>
            <td><input type="text" name="custHandphoneNo" id="custHandphoneNo" size="50"
                       value="${custDetail.custHandphoneNo}"
                    /><br/><br/></td>
        </tr>
        <tr>
            <td><h3 class="templatemo-gold">Phone No: </h3></td>
            <td><input type="text" name="custPhoneNo" id="custPhoneNo" size="50" value="${custDetail.custPhoneNo}"
                    /><br/><br/></td>
        </tr>
        <tr>
            <td><h3 class="templatemo-gold">Email: </h3></td>
            <td><input type="text" name="custEmail" id="custEmail" size="50" value="${custDetail.custEmail}"
                    /><br/><br/></td>
        </tr>
        <tr>
            <td><input type="submit" name="submit" value="Update" action="CustomerController?action=edit"
                       class="btn text-uppercase templatemo-btn templatemo-info-btn"></td>
            <td><input type="submit" name="submit" value="Delete"
                       class="btn text-uppercase templatemo-btn templatemo-info-btn"></td>
        </tr>

    </table>
</form>
2

There are 2 answers

0
6ton On

You are missing comma after end quote on these lines:

+ "custRegion = '"+cust.getCustRegion()+"' "
+ "custHandphoneNo = '"+cust.getCustHandphoneNo()+"' "
+ "custPhoneNo = '"+cust.getCustPhoneNo()+"' "

And please use PreparedStatement instead

0
Maheswaran Ravisankar On

You can use OraclePreparedStatement and bind variable using "names"

 OraclePreparedStatement statement = (OraclePreparedStatement)con.prepareStatement("UPDATE CUSTOMER "
                                        + " SET custName = :custName, "
                                        + " custAdd = :custAdd, "
                                        + " custRegion = :custRegion, "
                                        + " custHandphoneNo = :custHandphoneNo , "
                                        + " custPhoneNo = :custPhoneNo , "
                                        + " custEmail = :custEmail "
                                        + " WHERE cust_id = :cust_id ");

Bind the variables.

statement.setStringAtName("custName",cust.getCustName());
statement.setStringAtName("custAdd",cust.getCustAdd());
statement.setStringAtName("custRegion",cust.getCustRegion());
statement.setStringAtName("custHandphoneNo",cust.getCustHandphoneNo());
statement.setStringAtName("custPhoneNo",cust.getCustPhoneNo());
statement.setStringAtName("custEmail",cust.getCustEmail());
statement.setStringAtName("cust_id",cust.cust_id());

Execute the Query

ResultSet rs = statement.executeQuery();