how to insert date format yyyyMMddHHmmss in timestamp ?!! java +Cassandra + jemeter

2,941 views
Skip to first unread message

Imen Jaouani

unread,
Aug 20, 2014, 5:01:16 AM8/20/14
to java-dri...@lists.datastax.com
Hi all ;

I have to fill a table using jmeeter !
My Cassandra table include timestamp as a date form and with jmeter i use the function ${__time(yyyyMMddHHmmss)} wich return a date with yyyyMMddHHmmss form !
so how can i convert this form with java code to make it adequate to insert in timestamp field in the table ! thank you

Olivier Michallat

unread,
Aug 20, 2014, 5:16:09 AM8/20/14
to java-dri...@lists.datastax.com
Hi Imen,

The driver uses java.util.Date to map timestamp columns. If your question is how to convert a String into a java.util.Date, the answer is DateFormat.parse and you should easily find examples online (this is not specific to the driver).

On a side note, could you check your email client's configuration? You've been sending duplicate messages to the list a couple of times.


To unsubscribe from this group and stop receiving emails from it, send an email to java-driver-us...@lists.datastax.com.



--
Olivier Michallat
Drivers & Tools Engineer, DataStax

Imen Jaouani

unread,
Aug 20, 2014, 5:23:32 AM8/20/14
to java-dri...@lists.datastax.com
ok thank you !
i'm sorry , i will check :

Imen Jaouani

unread,
Aug 20, 2014, 5:27:55 AM8/20/14
to java-dri...@lists.datastax.com
i try to clarify :

Date d=new Date();
   
    select.putString("statement", "INSERT INTO arcdb.session (Session_id,User_oidval,mco,Service_type,sync_key,"
    + "terminal_type,counter,authentication_date,session_invalidation_date) values ('"+session_id+"',"+i_user_oidval+",'"+i_mco+"','"+i_service_type+"','"+i_sync_key+"','"+i_terminal_type+"','"+i_counter+"',"+d+","+d+")");
 

the error is :

{"status":"error","message":"[Cassandra Persistor] line 1:240 no viable alternative at input 'Aug'"}

Olivier Michallat

unread,
Aug 20, 2014, 6:00:20 AM8/20/14
to java-dri...@lists.datastax.com
Don't use string concatenation to build your queries. You should use bind markers and provide the values separately. For one-time queries use Session.execute(String, Object...) [1, 2], otherwise use prepared statements [3].

A few examples:

            // one-time statement
            session.execute("INSERT INTO foo (i) VALUES (?)", 1);

            // prepared statement
            PreparedStatement ps = session.prepare("INSERT INTO foo (i) VALUES (?)");
            session.execute(ps.bind(1));

            // prepared statement with named marker
            ps = session.prepare("INSERT INTO foo (i) VALUES (:value)");
            session.execute(ps.bind().setInt("value", 1));




To unsubscribe from this group and stop receiving emails from it, send an email to java-driver-us...@lists.datastax.com.
Reply all
Reply to author
Forward
0 new messages