You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@jmeter.apache.org by Raihan Jamal <ja...@gmail.com> on 2013/02/12 23:40:24 UTC

Insert JSON String using JMeter to database

I am working on the project in which I need to make a connection to
database and insert lot of rows in that Database. I have two columns
currently in that database-

*    ID                 String PrimaryKey*
*    ACCOUNT    String*

So I need to insert lot of rows in these two columns with the help of
JMeter. I am able to generate random Unique ID for ID column by using this-

*`${__BeanShell(UUID.randomUUID().toString())}`*

I am trying to insert `JSON String` into ACCOUNT columns using `JMeter`.
Below is the JSON string that I am trying to insert.

*`{"lv":[{"v":{"regId":null,"user":null,"Id":996},"cn":1}],"lmd":1360185}`*

In the parameter values section in JMeter, I am passing something like this-

*    ${__BeanShell(UUID.randomUUID().toString())}
,{"lv":[{"v":{"regId":null,"user":null,"Id":996},"cn":1}],"lmd":1360185}*


This is my SQL-

*`INSERT INTO TEST2 (id, account) values (?, ?)`*


But after trying to insert, I am getting this exception-

    Response message: java.io.IOException: Cannot have quote-char in plain
field:[{"]

How can I fix this thing? I just need to insert JSON string in the `ACCOUNT
column`

Any thoughts how to achieve this?





*Raihan Jamal*

Re: Insert JSON String using JMeter to database

Posted by Deepak Shetty <sh...@gmail.com>.
also if your json string uses " you can probably inline to use an update
statement with something like
insert into table(col1,col2) values ('${var1}','${var2}');
then you wont have to escape anything (unless your json also uses ')


On Tue, Feb 12, 2013 at 7:01 PM, Deepak Shetty <sh...@gmail.com> wrote:

> http://jmeter.apache.org/usermanual/component_reference.html#JDBC_Request
>
> The list must be enclosed in double-quotes if any of the values contain a
> comma or double-quote, and any embedded double-quotes must be doubled-up,
> for example:
>
> "Dbl-Quote: "" and Comma: ,"
>
>
>
>
> On Tue, Feb 12, 2013 at 2:40 PM, Raihan Jamal <ja...@gmail.com>wrote:
>
>> I am working on the project in which I need to make a connection to
>> database and insert lot of rows in that Database. I have two columns
>> currently in that database-
>>
>> *    ID                 String PrimaryKey*
>> *    ACCOUNT    String*
>>
>> So I need to insert lot of rows in these two columns with the help of
>> JMeter. I am able to generate random Unique ID for ID column by using
>> this-
>>
>> *`${__BeanShell(UUID.randomUUID().toString())}`*
>>
>> I am trying to insert `JSON String` into ACCOUNT columns using `JMeter`.
>> Below is the JSON string that I am trying to insert.
>>
>>
>> *`{"lv":[{"v":{"regId":null,"user":null,"Id":996},"cn":1}],"lmd":1360185}`*
>>
>> In the parameter values section in JMeter, I am passing something like
>> this-
>>
>> *    ${__BeanShell(UUID.randomUUID().toString())}
>> ,{"lv":[{"v":{"regId":null,"user":null,"Id":996},"cn":1}],"lmd":1360185}*
>>
>>
>> This is my SQL-
>>
>> *`INSERT INTO TEST2 (id, account) values (?, ?)`*
>>
>>
>> But after trying to insert, I am getting this exception-
>>
>>     Response message: java.io.IOException: Cannot have quote-char in plain
>> field:[{"]
>>
>> How can I fix this thing? I just need to insert JSON string in the
>> `ACCOUNT
>> column`
>>
>> Any thoughts how to achieve this?
>>
>>
>>
>>
>>
>> *Raihan Jamal*
>>
>
>

Re: Insert JSON String using JMeter to database

Posted by Deepak Shetty <sh...@gmail.com>.
Yes. should work
On Feb 12, 2013 10:54 PM, "Raihan Jamal" <ja...@gmail.com> wrote:

> Makes sense now. So if I am going with option 1, and If I am going to
> insert, it should be like this right?
>
> ${__BeanShell(UUID.randomUUID().toString())}
> ,"{""lv"":[{""v"":{""regId"":null,""
> user"":null,""Id"":996},""cn"":1}],""lmd"":1360185}"
>
>
> First is for one column and second is for other column. right?
>
>
> *Raihan Jamal*
>
>
> On Tue, Feb 12, 2013 at 10:35 PM, Deepak Shetty <sh...@gmail.com> wrote:
>
> > Option 1 :
> > {"lv":[{"v":{"regId":null,"
> > user":null,"Id":996},"cn":1}],"lmd":1360185} should become
> >
> > "{""lv"":[{""v"":{""regId"":null,""
> > user"":null,""Id"":996},""cn"":1}],""lmd"":1360185}" i.e. replace all
> > occurences of " by "" and quote the whole string.
> >
> > if you are using beanshell then just use the replaceAll function of a
> > String to do the above replacement
> >
> > Option 2 (riskier):
> > If you are absolutely certain that your JSON string cant contain an
> > apostrophe '  then in the JDBC Request , change the type to update
> > statement (instead of prepared update) and use something like
> >
> > INSERT INTO TEST2 (id, account) values ('${var1}', '${var2}')
> > where var1 and var2 are the variables with the values you want to insert.
> > If your json string (var2) doesnt have apostrophe then you dont need to
> do
> > anything else since " is not special for sql
> >
> >
> >
> >
> >
> >
> > On Tue, Feb 12, 2013 at 9:50 PM, Raihan Jamal <ja...@gmail.com>
> > wrote:
> >
> > > Thanks for the suggestion. But I am not sure, I understand what you
> said
> > > just now. Can you provide me an example what changes I need to make in
> > this
> > > JSON string so that I can insert into the Database-
> > >
> > >
> *{"lv":[{"v":{"regId":null,"user":null,"Id":996},"cn":1}],"lmd":1360185}*
> > >
> > >
> > > By that I will be able to understand much better.
> > >
> > > Thanks.
> > >
> > >
> > > *Raihan Jamal*
> > >
> > >
> > > On Tue, Feb 12, 2013 at 7:01 PM, Deepak Shetty <sh...@gmail.com>
> > wrote:
> > >
> > > >
> > >
> >
> http://jmeter.apache.org/usermanual/component_reference.html#JDBC_Request
> > > >
> > > > The list must be enclosed in double-quotes if any of the values
> > contain a
> > > > comma or double-quote, and any embedded double-quotes must be
> > doubled-up,
> > > > for example:
> > > >
> > > > "Dbl-Quote: "" and Comma: ,"
> > > >
> > > >
> > > >
> > > >
> > > > On Tue, Feb 12, 2013 at 2:40 PM, Raihan Jamal <jamalraihan@gmail.com
> >
> > > > wrote:
> > > >
> > > > > I am working on the project in which I need to make a connection to
> > > > > database and insert lot of rows in that Database. I have two
> columns
> > > > > currently in that database-
> > > > >
> > > > > *    ID                 String PrimaryKey*
> > > > > *    ACCOUNT    String*
> > > > >
> > > > > So I need to insert lot of rows in these two columns with the help
> of
> > > > > JMeter. I am able to generate random Unique ID for ID column by
> using
> > > > this-
> > > > >
> > > > > *`${__BeanShell(UUID.randomUUID().toString())}`*
> > > > >
> > > > > I am trying to insert `JSON String` into ACCOUNT columns using
> > > `JMeter`.
> > > > > Below is the JSON string that I am trying to insert.
> > > > >
> > > > >
> > > >
> > >
> >
> *`{"lv":[{"v":{"regId":null,"user":null,"Id":996},"cn":1}],"lmd":1360185}`*
> > > > >
> > > > > In the parameter values section in JMeter, I am passing something
> > like
> > > > > this-
> > > > >
> > > > > *    ${__BeanShell(UUID.randomUUID().toString())}
> > > > >
> > >
> ,{"lv":[{"v":{"regId":null,"user":null,"Id":996},"cn":1}],"lmd":1360185}*
> > > > >
> > > > >
> > > > > This is my SQL-
> > > > >
> > > > > *`INSERT INTO TEST2 (id, account) values (?, ?)`*
> > > > >
> > > > >
> > > > > But after trying to insert, I am getting this exception-
> > > > >
> > > > >     Response message: java.io.IOException: Cannot have quote-char
> in
> > > > plain
> > > > > field:[{"]
> > > > >
> > > > > How can I fix this thing? I just need to insert JSON string in the
> > > > `ACCOUNT
> > > > > column`
> > > > >
> > > > > Any thoughts how to achieve this?
> > > > >
> > > > >
> > > > >
> > > > >
> > > > >
> > > > > *Raihan Jamal*
> > > > >
> > > >
> > >
> >
>

Re: Insert JSON String using JMeter to database

Posted by Raihan Jamal <ja...@gmail.com>.
Makes sense now. So if I am going with option 1, and If I am going to
insert, it should be like this right?

${__BeanShell(UUID.randomUUID().toString())}
,"{""lv"":[{""v"":{""regId"":null,""
user"":null,""Id"":996},""cn"":1}],""lmd"":1360185}"


First is for one column and second is for other column. right?


*Raihan Jamal*


On Tue, Feb 12, 2013 at 10:35 PM, Deepak Shetty <sh...@gmail.com> wrote:

> Option 1 :
> {"lv":[{"v":{"regId":null,"
> user":null,"Id":996},"cn":1}],"lmd":1360185} should become
>
> "{""lv"":[{""v"":{""regId"":null,""
> user"":null,""Id"":996},""cn"":1}],""lmd"":1360185}" i.e. replace all
> occurences of " by "" and quote the whole string.
>
> if you are using beanshell then just use the replaceAll function of a
> String to do the above replacement
>
> Option 2 (riskier):
> If you are absolutely certain that your JSON string cant contain an
> apostrophe '  then in the JDBC Request , change the type to update
> statement (instead of prepared update) and use something like
>
> INSERT INTO TEST2 (id, account) values ('${var1}', '${var2}')
> where var1 and var2 are the variables with the values you want to insert.
> If your json string (var2) doesnt have apostrophe then you dont need to do
> anything else since " is not special for sql
>
>
>
>
>
>
> On Tue, Feb 12, 2013 at 9:50 PM, Raihan Jamal <ja...@gmail.com>
> wrote:
>
> > Thanks for the suggestion. But I am not sure, I understand what you said
> > just now. Can you provide me an example what changes I need to make in
> this
> > JSON string so that I can insert into the Database-
> >
> > *{"lv":[{"v":{"regId":null,"user":null,"Id":996},"cn":1}],"lmd":1360185}*
> >
> >
> > By that I will be able to understand much better.
> >
> > Thanks.
> >
> >
> > *Raihan Jamal*
> >
> >
> > On Tue, Feb 12, 2013 at 7:01 PM, Deepak Shetty <sh...@gmail.com>
> wrote:
> >
> > >
> >
> http://jmeter.apache.org/usermanual/component_reference.html#JDBC_Request
> > >
> > > The list must be enclosed in double-quotes if any of the values
> contain a
> > > comma or double-quote, and any embedded double-quotes must be
> doubled-up,
> > > for example:
> > >
> > > "Dbl-Quote: "" and Comma: ,"
> > >
> > >
> > >
> > >
> > > On Tue, Feb 12, 2013 at 2:40 PM, Raihan Jamal <ja...@gmail.com>
> > > wrote:
> > >
> > > > I am working on the project in which I need to make a connection to
> > > > database and insert lot of rows in that Database. I have two columns
> > > > currently in that database-
> > > >
> > > > *    ID                 String PrimaryKey*
> > > > *    ACCOUNT    String*
> > > >
> > > > So I need to insert lot of rows in these two columns with the help of
> > > > JMeter. I am able to generate random Unique ID for ID column by using
> > > this-
> > > >
> > > > *`${__BeanShell(UUID.randomUUID().toString())}`*
> > > >
> > > > I am trying to insert `JSON String` into ACCOUNT columns using
> > `JMeter`.
> > > > Below is the JSON string that I am trying to insert.
> > > >
> > > >
> > >
> >
> *`{"lv":[{"v":{"regId":null,"user":null,"Id":996},"cn":1}],"lmd":1360185}`*
> > > >
> > > > In the parameter values section in JMeter, I am passing something
> like
> > > > this-
> > > >
> > > > *    ${__BeanShell(UUID.randomUUID().toString())}
> > > >
> > ,{"lv":[{"v":{"regId":null,"user":null,"Id":996},"cn":1}],"lmd":1360185}*
> > > >
> > > >
> > > > This is my SQL-
> > > >
> > > > *`INSERT INTO TEST2 (id, account) values (?, ?)`*
> > > >
> > > >
> > > > But after trying to insert, I am getting this exception-
> > > >
> > > >     Response message: java.io.IOException: Cannot have quote-char in
> > > plain
> > > > field:[{"]
> > > >
> > > > How can I fix this thing? I just need to insert JSON string in the
> > > `ACCOUNT
> > > > column`
> > > >
> > > > Any thoughts how to achieve this?
> > > >
> > > >
> > > >
> > > >
> > > >
> > > > *Raihan Jamal*
> > > >
> > >
> >
>

Re: Insert JSON String using JMeter to database

Posted by Deepak Shetty <sh...@gmail.com>.
Option 1 :
{"lv":[{"v":{"regId":null,"
user":null,"Id":996},"cn":1}],"lmd":1360185} should become

"{""lv"":[{""v"":{""regId"":null,""
user"":null,""Id"":996},""cn"":1}],""lmd"":1360185}" i.e. replace all
occurences of " by "" and quote the whole string.

if you are using beanshell then just use the replaceAll function of a
String to do the above replacement

Option 2 (riskier):
If you are absolutely certain that your JSON string cant contain an
apostrophe '  then in the JDBC Request , change the type to update
statement (instead of prepared update) and use something like

INSERT INTO TEST2 (id, account) values ('${var1}', '${var2}')
where var1 and var2 are the variables with the values you want to insert.
If your json string (var2) doesnt have apostrophe then you dont need to do
anything else since " is not special for sql






On Tue, Feb 12, 2013 at 9:50 PM, Raihan Jamal <ja...@gmail.com> wrote:

> Thanks for the suggestion. But I am not sure, I understand what you said
> just now. Can you provide me an example what changes I need to make in this
> JSON string so that I can insert into the Database-
>
> *{"lv":[{"v":{"regId":null,"user":null,"Id":996},"cn":1}],"lmd":1360185}*
>
>
> By that I will be able to understand much better.
>
> Thanks.
>
>
> *Raihan Jamal*
>
>
> On Tue, Feb 12, 2013 at 7:01 PM, Deepak Shetty <sh...@gmail.com> wrote:
>
> >
> http://jmeter.apache.org/usermanual/component_reference.html#JDBC_Request
> >
> > The list must be enclosed in double-quotes if any of the values contain a
> > comma or double-quote, and any embedded double-quotes must be doubled-up,
> > for example:
> >
> > "Dbl-Quote: "" and Comma: ,"
> >
> >
> >
> >
> > On Tue, Feb 12, 2013 at 2:40 PM, Raihan Jamal <ja...@gmail.com>
> > wrote:
> >
> > > I am working on the project in which I need to make a connection to
> > > database and insert lot of rows in that Database. I have two columns
> > > currently in that database-
> > >
> > > *    ID                 String PrimaryKey*
> > > *    ACCOUNT    String*
> > >
> > > So I need to insert lot of rows in these two columns with the help of
> > > JMeter. I am able to generate random Unique ID for ID column by using
> > this-
> > >
> > > *`${__BeanShell(UUID.randomUUID().toString())}`*
> > >
> > > I am trying to insert `JSON String` into ACCOUNT columns using
> `JMeter`.
> > > Below is the JSON string that I am trying to insert.
> > >
> > >
> >
> *`{"lv":[{"v":{"regId":null,"user":null,"Id":996},"cn":1}],"lmd":1360185}`*
> > >
> > > In the parameter values section in JMeter, I am passing something like
> > > this-
> > >
> > > *    ${__BeanShell(UUID.randomUUID().toString())}
> > >
> ,{"lv":[{"v":{"regId":null,"user":null,"Id":996},"cn":1}],"lmd":1360185}*
> > >
> > >
> > > This is my SQL-
> > >
> > > *`INSERT INTO TEST2 (id, account) values (?, ?)`*
> > >
> > >
> > > But after trying to insert, I am getting this exception-
> > >
> > >     Response message: java.io.IOException: Cannot have quote-char in
> > plain
> > > field:[{"]
> > >
> > > How can I fix this thing? I just need to insert JSON string in the
> > `ACCOUNT
> > > column`
> > >
> > > Any thoughts how to achieve this?
> > >
> > >
> > >
> > >
> > >
> > > *Raihan Jamal*
> > >
> >
>

Re: Insert JSON String using JMeter to database

Posted by Raihan Jamal <ja...@gmail.com>.
Thanks for the suggestion. But I am not sure, I understand what you said
just now. Can you provide me an example what changes I need to make in this
JSON string so that I can insert into the Database-

*{"lv":[{"v":{"regId":null,"user":null,"Id":996},"cn":1}],"lmd":1360185}*


By that I will be able to understand much better.

Thanks.


*Raihan Jamal*


On Tue, Feb 12, 2013 at 7:01 PM, Deepak Shetty <sh...@gmail.com> wrote:

> http://jmeter.apache.org/usermanual/component_reference.html#JDBC_Request
>
> The list must be enclosed in double-quotes if any of the values contain a
> comma or double-quote, and any embedded double-quotes must be doubled-up,
> for example:
>
> "Dbl-Quote: "" and Comma: ,"
>
>
>
>
> On Tue, Feb 12, 2013 at 2:40 PM, Raihan Jamal <ja...@gmail.com>
> wrote:
>
> > I am working on the project in which I need to make a connection to
> > database and insert lot of rows in that Database. I have two columns
> > currently in that database-
> >
> > *    ID                 String PrimaryKey*
> > *    ACCOUNT    String*
> >
> > So I need to insert lot of rows in these two columns with the help of
> > JMeter. I am able to generate random Unique ID for ID column by using
> this-
> >
> > *`${__BeanShell(UUID.randomUUID().toString())}`*
> >
> > I am trying to insert `JSON String` into ACCOUNT columns using `JMeter`.
> > Below is the JSON string that I am trying to insert.
> >
> >
> *`{"lv":[{"v":{"regId":null,"user":null,"Id":996},"cn":1}],"lmd":1360185}`*
> >
> > In the parameter values section in JMeter, I am passing something like
> > this-
> >
> > *    ${__BeanShell(UUID.randomUUID().toString())}
> > ,{"lv":[{"v":{"regId":null,"user":null,"Id":996},"cn":1}],"lmd":1360185}*
> >
> >
> > This is my SQL-
> >
> > *`INSERT INTO TEST2 (id, account) values (?, ?)`*
> >
> >
> > But after trying to insert, I am getting this exception-
> >
> >     Response message: java.io.IOException: Cannot have quote-char in
> plain
> > field:[{"]
> >
> > How can I fix this thing? I just need to insert JSON string in the
> `ACCOUNT
> > column`
> >
> > Any thoughts how to achieve this?
> >
> >
> >
> >
> >
> > *Raihan Jamal*
> >
>

Re: Insert JSON String using JMeter to database

Posted by Deepak Shetty <sh...@gmail.com>.
http://jmeter.apache.org/usermanual/component_reference.html#JDBC_Request

The list must be enclosed in double-quotes if any of the values contain a
comma or double-quote, and any embedded double-quotes must be doubled-up,
for example:

"Dbl-Quote: "" and Comma: ,"




On Tue, Feb 12, 2013 at 2:40 PM, Raihan Jamal <ja...@gmail.com> wrote:

> I am working on the project in which I need to make a connection to
> database and insert lot of rows in that Database. I have two columns
> currently in that database-
>
> *    ID                 String PrimaryKey*
> *    ACCOUNT    String*
>
> So I need to insert lot of rows in these two columns with the help of
> JMeter. I am able to generate random Unique ID for ID column by using this-
>
> *`${__BeanShell(UUID.randomUUID().toString())}`*
>
> I am trying to insert `JSON String` into ACCOUNT columns using `JMeter`.
> Below is the JSON string that I am trying to insert.
>
> *`{"lv":[{"v":{"regId":null,"user":null,"Id":996},"cn":1}],"lmd":1360185}`*
>
> In the parameter values section in JMeter, I am passing something like
> this-
>
> *    ${__BeanShell(UUID.randomUUID().toString())}
> ,{"lv":[{"v":{"regId":null,"user":null,"Id":996},"cn":1}],"lmd":1360185}*
>
>
> This is my SQL-
>
> *`INSERT INTO TEST2 (id, account) values (?, ?)`*
>
>
> But after trying to insert, I am getting this exception-
>
>     Response message: java.io.IOException: Cannot have quote-char in plain
> field:[{"]
>
> How can I fix this thing? I just need to insert JSON string in the `ACCOUNT
> column`
>
> Any thoughts how to achieve this?
>
>
>
>
>
> *Raihan Jamal*
>