returning auto incremented id

4.x.x
inosh-perera 10 years ago
parent 92503ac0fe
commit 40ee310f42

@ -13,10 +13,10 @@ public interface OperationDAO {
/**
* Add a new operation to plugin operation table.
* @param operation Operation object that holds data related to the operation to be inserted.
* @return The status of the operation. If the insert was successful or not.
* @return The last inserted Id is returned, if the insertion was unsuccessful -1 is returned.
* @throws MobileDeviceManagementDAOException
*/
boolean addOperation(Operation operation) throws MobileDeviceManagementDAOException;
int addOperation(Operation operation) throws MobileDeviceManagementDAOException;
/**
* Update a operation in the operation table.

@ -26,9 +26,9 @@ public class OperationDAOImpl implements OperationDAO {
}
@Override
public boolean addOperation(Operation operation)
public int addOperation(Operation operation)
throws MobileDeviceManagementDAOException {
boolean status = false;
int status = -1;
Connection conn = null;
PreparedStatement stmt = null;
try {
@ -36,12 +36,15 @@ public class OperationDAOImpl implements OperationDAO {
String createDBQuery =
"INSERT INTO MBL_OPERATION(FEATURE_CODE, CREATED_DATE) VALUES ( ?, ?)";
stmt = conn.prepareStatement(createDBQuery);
stmt = conn.prepareStatement(createDBQuery, new String[] { "OPERATION_ID" });
stmt.setString(1, operation.getFeatureCode());
stmt.setInt(2, operation.getCreatedDate());
int rows = stmt.executeUpdate();
if (rows > 0) {
status = true;
ResultSet rs = stmt.getGeneratedKeys();
if (rs != null && rs.next()) {
status = rs.getInt(1);
}
}
} catch (SQLException e) {
String msg = "Error occurred while adding feature code - '" +

@ -86,6 +86,7 @@ public class ServerDetails extends Activity {
getResources().getString(R.string.shared_pref_ip));
regId = Preference.get(context.getApplicationContext().getApplicationContext(), getResources().getString(R.string.shared_pref_regId));
//heck if we have the IP saved previously.
if (ipSaved != null) {
serverIP.setText(ipSaved);
CommonUtilities.setServerURL(ipSaved);

Loading…
Cancel
Save