JMeter: Inserting record into database by using JDBC request - jmeter

I have configured JDBC connection in my JMeter test plan.
The database settings in JDBC connection are configured correctly.
I am extracting employee id from one of my requests response.(i.e Employee_Id)
By using BSF PostProcessor, i have stored the employee id into a variable called as Emp_ID
I want to insert the extracted employee id into my database.
Database used is Oracle SQL developer, Version 4.0.1.14,Build MAIN-14.48.
Table name is : Employee_Details
Column name is : Employee_id ,Datatype: VARCHAR2
In JDBC request,i have selected "Query Type" as "Update Statement" and entered the following query:
Query 1: INSERT INTO Employee_Details (Employee_id)
VALUES (${Emp_ID})
Query 2: INSERT Employee_id='${Emp_ID}'
Parameter Types is given as VARCHAR2.
On both the execution, JMeter displays error as "Cannot create PoolableConnectionFactory (ORA-00923: FROM keyword not found where expected)"
Please provide your valuable suggestion on this.

I found a workaround for this that avoids having problems:
JDBC Request Query Type needs to be: Update Statement
The query needs to be processed as a block
BEGIN
SQL Statement
END;

My expectation is that you have incorrect validation query:
If you left the "Validation Query" box value default - Select 1 - Oracle may not like it very much. You need to change it to select 1 from dual
References:
DBCP - validationQuery for different Databases
The Real Secret to Building a Database Test Plan With JMeter
ORA-00923: FROM keyword not found where expected tips

There are 3 things as follows:
Check the validation query and keep it blank. Screenshot is attached
When you are executing insert query, keep Query Type as Updated
When you are executing query please add database.tablename and then execute.

Related

SYS_B_x in Oracle query result column name

I've faced with some weird behaviour of Oracle 11 DB.
I have a simple query selecting data from a view:
select
(case when exists(select 1 from MY_VIEW v where v.func_name = 'NAME') then 1 else 0 end)
from dual
MY_VIEW looks like:
CREATE OR REPLACE VIEW MY_VIEW
AS
SELECT a.object_name AS func_name, NULL AS func_desc
FROM USER_ARGUMENTS a
In the result set, I receive result with columnName: (CASEWHENEXISTS(SELECT:"SYS_B_0"FROMMY_VIEWVWHEREV.FUNC_VALUE=:"SYS_B_1")THEN:"SYS_B_2"ELSE:"SYS_B_3"END)
And when I'm trying to execute this query by Hibernate, it falls with error
SQL Error: 17133 "Invalid identifier or literal"
while extracting column alias.
Error causes when I'm using ojdbc8 driver, with ojdbc6 driver all is OK.
Strange thing is that I have problems only when I'm querying from this particular view.
When I made same query from another View, created from simple table, everything was ok.
Furthermore, I have another Oracle 11 DB and there result set column name for this query looks common:
(CASEWHENEXISTS(SELECT1FROMMY_VIEWVWHEREV.FUNC_VALUE='NAME')THEN1ELSE0END)
My question is: why and when Oracle replaces values in query string on :"SYS_B_x" ?
First of all, you need to add an alias for that column.
You get :SYS_B_x because of the parameter cursor_sharing=force on that database.

In Jmeter, JDBC Request is returning only name of column with no values for a Select query

My Environment: JMeter v3.2, Oracle 11, java 1.8
I am able to successfully establish JDBC connection to the database using JDBC Connection Configuration.
However, the JDBC Request in which i am executing a select query.
I am getting only the name of the column in result with empty value.
I've confirmed the SQL is fine by running the SQL in Oracle Developer, data is returned successfully.
My workings:
JDBC Request --> Query Type: Select Statement
select policy_code from bas_policy where policy_code='KP550 '
When I run the JDBC Request - the report in the View Results Tree Listener shows successful execution.
Response data in Debug Sampler:
JMeterVariables:
JMeterThread.last_sample_ok=true
JMeterThread.pack=org.apache.jmeter.threads.SamplePackage#15ec91
Pool1=org.apache.jmeter.protocol.jdbc.config.DataSourceElement
$DataSourceComponentImpl#cfef05
START.HMS=164422
START.MS=1496936662485
START.YMD=20170608
TESTSTART.MS=1496939556814
a_#=0
result=[]
Where 'a' is defined as the Variable name.
Response data in Debug Sampler
POLICY_CODE
Again, as with all my posts, I am grateful for all advice/help etc.
SOLVED. Have to use the VPD (virtual private database) id for the child instance in the query. the correct query is select POLICYN,STATUS from bas_policy#cloud_dbid_3.world

Oracle - Log the executed query

I have to debug stored procedure which contains a few SQL queries. One of them contains an error. So, I need to execute this SQL query with parameters in other window. I found next query that would help me:
select v.SQL_TEXT
from v$sql v
Unfortunately, this field restricted by 1Kb. In my case I have quite big SQL query and Oracle truncates it. How to log the executed query? I use PL/SQL Developer 10 and Oracle 9i
Unfortunately, this field restricted by 1Kb
If you need the full SQL, then use the SQL_FULLTEXT which is a CLOB datatype instead of SQL_TEXT whcih is limited to first 1000 characters.
From documentation,
Column Datatype Description
------ -------------- ---------------------------------------
SQL_TEXT VARCHAR2(1000) First thousand characters of the SQL
text for the current cursor
SQL_FULLTEXT CLOB Full text for the SQL statement exposed
as a CLOB column. The full text of a SQL
statement can be retrieved using this
column instead of joining with the
V$SQL_TEXT dynamic performance view.
So, use:
SELECT SQL_FULLTEXT FROM v$sql;
By the way, seems like you are actually looking for tracing your session to get the complete details of the procedure and the SQL statements involved. I would suggest to trace the session with level 4 i.e. with the addition of bind variable values.
See How to generate trace file – SQL Trace and TKPROF in Oracle

JDBC Error in insert with DB2 (works with Sql Server)

I use in a Java Application JDBC to query the DBMS. The application works correctly with Sql Server but I get this error in DB2 during one insert:
com.ibm.db2.jcc.am.SqlDataException: DB2 SQL Error: SQLCODE=-302, SQLSTATE=22001, SQLERRMC=1, DRIVER=3.63.75
The insert is made using the ResultSet.TYPE_SCROLL_SENSITIVE, ResultSet.CONCUR_UPDATABLE.
My query is a plain select of the table, then I declare my PreparedStatement, passing the parameters and afterwards with the ResultSet I do first the moveToInsertRow() and then the insertRow().
Do you know if there are any problems with this approach using DB2?
As I told you before the same code works correctly with Sql Server.
SQL Code -302 on DB2 means:
THE VALUE OF INPUT VARIABLE OR PARAMETER NUMBER position-number IS INVALID OR TOO LARGE FOR THE TARGET COLUMN OR THE TARGET VALUE
So it seems like you are trying to insert a value into a column which is too large or too short (e.g. Hello World into a varchar(5)). Probably the column has a different length in DB2 and sql-server or you are inserting different values.
Probably too late to add to this thread.. but someone else might find it useful
Got the same SQL Exception when trying to do a SELECT : didn't realize the property value in WHERE clause was exceeding the limit on the corresponding column
SELECT * FROM <schema>.<table_name> WHERE PropertyName = 'value';
value was a VARCHAR type but exceeded the Length limit
Detailed exception does say it clearly that data integrity was violated: org.springframework.dao.DataIntegrityViolationException
So a good idea would be to do a length check on the value(s) that are being set on the properties before firing any queries to the database.

INSERT SELECT not working

Using Informix 11.7, I'm trying to execute a INSERT SELECT query with jdbc positional parameters in the select statement like this :
INSERT INTO table1(id, code, label)
SELECT ?, ?, ? FROM table2
WHERE ...
Parameters are set like this :
stmt.setString(1, "auniqueid");
stmt.setString(2, "code");
stmt.setString(3, "coollabel");
I get the following error :
Exception in thread "main" java.sql.SQLException: A syntax error has occurred.
When positional parmeters "?" are placed elsewhere it works fine. I have not this problem using PostgreSQL. What's wrong with my query ? I use the Informix JDBC Driver v3.70 JC1.
Thanks for your help.
Are you expecting to get column names specified via the placeholders? If so, you're on a hiding to nothing; you cannot use placeholders for structural elements of a query such as column or table names. They can only ever replace values. If you want dynamic SQL to specify the columns, use dynamic SQL; create a string with the content:
INSERT INTO table1(id, code, label)
SELECT auniqueid, code, coollabel
FROM table2
WHERE ...
and work with that.
If those placeholders were going to be values, then you'd be inserting the same values over and over, once for each row returned by the query, and that normally isn't what you'd want; you'd simply insert one row with a VALUES clause, where placeholders are permitted:
INSERT INTO table1(id, code, label) VALUES(?, ?, ?);
That would work fine.
AFAIK, this behaviour conforms to the SQL standard. If it works differently in PostgreSQL, then PostgreSQL has provided an extension to the standard.
Warning: I have no experience with Informix, answer is based on general observations
When specifying parameters the database will need to know the type of each parameter. If a parameter occurs in the select-list, then there is no way for the database to infer the type of the parameter. Some database might be capable of delaying that decision until it actually receives the parameters, but most database will need to know this at parse time. This is probably the reason why you receive the error.
Some databases - I don't know if this applies to Informix - allow you to cast parameters. So for example:
SELECT CAST(? AS VARCHAR(20)), CAST(? AS VARCHAR(10)), CAST(? AS VARCHAR(5)) FROM ...
In that case the database will be able to infer the parameter types and be able to parse the query correctly.
With this I do assume you are not trying to specify columnnames for the select-list using parameters, as that is not possible.

Resources