While inserting the entry into the dynamodb table, I am getting the follwing error:
com.amazonaws.services.dynamodbv2.model.ConditionalCheckFailedException:
The conditional request failed (Service: AmazonDynamoDBv2; Status
Code: 400; Error Code: ConditionalCheckFailedException;
This is my Java code for inserting the element:
DynamoDBSaveExpression expression = (new DynamoDBSaveExpression()).withExpectedEntry("itemKey", new ExpectedAttributeValue(false));
try {
this.mapper.save(itemKeyMapping, expression);
} catch (Exception var3) {
this.logger.error("", var3);
throw var3;
}
itemKeyMapping is an object which has a member variable as itemKey.
So, it should work. The condition is just saying that itemKey should exist, right?
Please let me know if I am doing some mistake.
My understanding is here was wrong. Actually, condition above means that insert only when itemKey attribute value in the database does not exist.
Related
I want to do the exception handling in Jmeter.Webdriver Webdriver Sampler
Please let me , How to use try/catch block in Jmeter.Webdriver webdriver Sampler ?
You can do this via normal JavaScript try block, here is an example of taking a screenshot when error occurs:
var pkg = JavaImporter(org.openqa.selenium)
var support_ui = JavaImporter(org.openqa.selenium.support.ui.WebDriverWait)
var conditions = org.openqa.selenium.support.ui.ExpectedConditions
var wait = new support_ui.WebDriverWait(WDS.browser, 5)
var exception = null
WDS.sampleResult.sampleStart()
try {
WDS.browser.get('http://example.com')
wait.until(conditions.presenceOfElementLocated(pkg.By.linkText('Not existing link')))
} catch (err) {
WDS.log.error(err.message)
var screenshot = WDS.browser.getScreenshotAs(pkg.OutputType.FILE)
screenshot.renameTo(java.io.File('screenshot.png'))
exception = err
} finally {
throw (exception)
}
WDS.sampleResult.sampleEnd())
Don't forget to "throw" the error after you handle it otherwise it will be "swallowed" and you get a false positive result.
See The WebDriver Sampler: Your Top 10 Questions Answered article for more tips and tricks
Surround the code with try block and add catch block at the end by giving variable name to capture the exception. (in the example, it is exc)
try as follows:
try{
WDS.sampleResult.sampleStart()
WDS.browser.get('http://jmeter-plugins.org')
var pkg = JavaImporter(org.openqa.selenium)
WDS.browser.findElement(pkg.By.id('what')) // there is no such element with id what
WDS.sampleResult.sampleEnd()
}
catch(exc){ //exc variable name
WDS.log.error("element not found" + exc)
}
in the JMeter log, you can see the complete trace of NoSuchElementException, which is raised when trying to find the element by id with the values as what, which is not present in the HTML.
Note: use View Results in Table to see the Sampler response time.
Reference:
https://jmeter-plugins.org/wiki/WebDriverSampler/
Reference Image:
It is same as how do you do in other IDEs like eclipse.
you can see below code
//try block starts here
try{
wait.until(ExpectedConditions.visibilityOfElementLocated(By.xpath("element"))).click();
}
catch(Exception e)
{
WDS.log.info("Exception is : " +e);//you can print the exception in jmeter log.
}
double quotes should be replaced with the single quote if you are using javascript Since the BeanShell is easy and it is similar to java use BeanShell as much as possible
I try setting an attribute for a session and want to assign a String to it, that is displayed later in a jsp.
I have the following code:
The System.out results in null even thought the String was set to the error message? What am I doing wrong?
error = "Something";
session.setAttribute("error", error);
System.out.println("This is get Attr: " +session.getAttribute(error));
I added the following lines of code now:
RequestDispatcher disp = req.getRequestDispatcher("error.jsp");
disp.forward(req, resp);
and in my jsp:
Hello ${error}
and it is displaying ${error} instead of the value!
You need to access the object by key:
System.out.println("This is get Attr: " +session.getAttribute("error"));
In your example, you are using the value (i.e.the object reference error)
I'm waaaay above my level of understanding here but have a simple request to change the sort order of data in a .NET datagrid. The system seems to use SubSonic to do the database queries, so there's a level of abstraction which I just don't understand and can't seem to guess at ;).
There is a line under the gridview control in the .aspx file like this:
<asp:ObjectDataSource ID="odsCsvReport" runat="server" SelectMethod="FetchAll" TypeName="WFlower.CsvReportController">
</asp:ObjectDataSource>
I've searched the project for 'CsvReportController' and there is a file in App_Code called 'CsvReportController.cs' in which there's a class like this:
[DataObjectMethod(DataObjectMethodType.Select, true)]
public CsvReportCollection FetchAll()
{
CsvReportCollection coll = new CsvReportCollection();
Query qry = new Query(CsvReport.Schema);
//qry.OrderDesc("CsvReportID");
coll.LoadAndCloseReader(qry.ExecuteReader());
return coll;
}
Now, I've just no idea how to get this data to be sorted by the 'CsvReportID' field in descending order (currently it's ascending).
Can anyone shed any light on this. Like I say, I'm in too deep here but it should be such a minor thing to do I'm determined to get to the bottom of it!
Thanks folks!
EDIT:
Okay, so as per #Mike Walsh's comment below, I tried this instead:
var qry = new Select().From(CsvReport.Schema);
qry.OrderDesc(new [] {CsvReport.Columns.AssignedToID});
return qry.ExecuteAsCollection<CsvReportCollection>();
Now however, this throws a completely different error elsewhere:
Violation of PRIMARY KEY constraint 'PK__OrdersToDelete__245EFE8C'. Cannot insert duplicate key in object 'dbo.OrdersToDelete'.
The statement has been terminated.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
Exception Details: System.Data.SqlClient.SqlException: Violation of PRIMARY KEY constraint 'PK__OrdersToDelete__245EFE8C'. Cannot insert duplicate key in object 'dbo.OrdersToDelete'.
The statement has been terminated.
Source Error:
Line 187: //Do database management.
Line 188: int removedUsers = SPs.Hg_DeleteInactiveUsers(14).Execute();
Line 189: int removedOrders = SPs.Hg_DeleteInactiveOrders(14).Execute();
Line 190: }
Can't remember the exact differences in 2.1-2.2-2.3 but will this compile for you?
var qry = new Select().From(CsvReport.Schema);
qry.OrderDesc(new [] {CsvReport.Columns.AssignedToID});
return qry.ExecuteAsCollection<CsvReportCollection>();
So I have this old code being used, that runs simple ExecuteNonQuery command for database calls. I'm using DbConnection, DbTransaction and other System.Data.Common commands.
I seem to get a lot of Null Reference errors whenever I use the function in certain parts of the project, though it seems fine in other parts. I think it has to do with opening connections manually or some problem with calling it, but I'm wondering if the function itself is badly designed originally (shouldn't there be a way to fix any problems in the way it is called?)
I feel when transactions are involved, these null reference errors come up more often, I think the error I get is null exception at "_command = _db.GetStoredProcCommand(storedProcedure);" inside the following function. But that stored procedure does exist, so it makes no sense.
public List<OutputParameter> execute(String storedProcedure, StoredProcedureParameter[] sqlParameters)
{
try
{
List<OutputParameter> outputParameters = new List<OutputParameter>();
_command = _db.GetStoredProcCommand(storedProcedure);
for (int x = 0; x < sqlParameters.GetLength(0); x++)
{
if (sqlParameters[x] != null)
{
StoredProcedureParameter sqlParameter = sqlParameters[x];
String param = sqlParameter.ParameterName;
DbType dbType = sqlParameter.DbType;
object value = sqlParameter.Value;
if (sqlParameter.IsOutputParam)
{
_db.AddOutParameter(_command, param, dbType, 32);
OutputParameter outputParameter = new OutputParameter(param);
outputParameters.Add(outputParameter);
}
else
_db.AddInParameter(_command, param, dbType, value);
}
}
if (_transaction == null)
_db.ExecuteNonQuery(_command);
else
_db.ExecuteNonQuery(_command, _transaction);
foreach (OutputParameter op in outputParameters)
{
op.ParameterValue = _db.GetParameterValue(_command, op.ParameterName);
}
return outputParameters;
}
catch (SqlException sqle)
{
throw new DataAccessException(sqle.ToString());
}
catch (Exception e)
{
throw new DataAccessException(e.ToString());
}
}
Your _command variable appears to be a field and as such a shared member.
As such your code is very susceptible to multithreading issues (if two functions call this class with different stored procedures, what happens?).
A Command should also be closed and disposed of properly, which is not happening in your code, not explicitly anyways.
If you are getting a null reference exception in the line _command = _db.GetStoredProcCommand(storedProcedure); then the only thing that can be null there is _db. The storedProcedure is just a parameter and _command could happily be null without a problem.
Since you aren't actually doing anything in the code to make sure that _db exists and is valid, open, etc. then this is most likely the problem.
I'd like to see what is about to be sent to the SQL Server from my SqlCommand before SQLCmd.ExecuteNonQuery() runs.
I'm trying to debug because I am receiving the following error: System.FormatException: Failed to convert parameter value from a String to a Int32.
Normally, I would use SQL Server Profiler to view what is being sent to SQL Server, but my statement is not making it that far.
Is there a way to determine what it is trying to convert? I am having problems determining which parameter is causing the error.
There's nothing that can quickly visualize it for you, but you can browse through the object and get at the internal list of parameters and view their names and values individually.
It will likely be faster just to write something that you can pass the command into and it will print out the name, DbType, Value.ToString() and Value.GetType().Name for each parameter.
void PrintCommand(DbCommand command)
{
Console.WriteLine("CommandType: {0}", command.CommandType);
Console.WriteLine("CommandText: {0}", command.CommandText);
foreach(var parameter in command.Parameters)
{
Console.WriteLine(" Parameter {0}, {1}: \"{2}\" ({3})",
parameter.ParameterName,
parameter.DbType,
parameter.Value,
parameter.Value.GetType().Name);
}
}
Try the immediate window:
? SQLCmd.Parameters["#MyParam"].Value