theangryangel / logstash-output-jdbc

JDBC output for Logstash
MIT License
255 stars 101 forks source link

Not able to put right insert query, example does not work properly and it is confusing #104

Closed rkhapre closed 7 years ago

rkhapre commented 7 years ago

Hi I am using Oracle DB I have below json value as coming from input and i want to insert this in Oracle DB

{
customer_id :1234: 
cust_name : abc
cust_add: Japan
}

My output parameters

output {
    jdbc {
        connection_string => "jdbc:oracle:thin:dc/dc@XXX.XX.X.XX1521:abcs"
        driver_jar_path => "F:/logstash-5.6.1/lib/ojdbc7.jar"
        statement => [ "INSERT INTO CUSTOMER(customer_id,cust_name,cust_add)VALUES(?,?,?)","customer_id","cust_name","cust_add"]
    }
}

The above one inserts null records

output {
    jdbc {
        connection_string => "jdbc:oracle:thin:dc/dc@XXX.XX.X.XX1521:abcs"
        driver_jar_path => "F:/logstash-5.6.1/lib/ojdbc7.jar"
        statement => [ "INSERT INTO CUSTOMER(customer_id,cust_name,cust_add)VALUES(?,?,?)","%{customer_id}","%{cust_name}","%{cust_add}"]
    }
}

The above one give error

Please let me know what will be the right insert query here to insert the value from input. I tried sprint format but it does not work. In the example conf file there is no traces of sprint format

hard-working-boy commented 7 years ago

add driver class mysql or oracle or something else like: driver_class => "com.mysql.jdbc.Driver"

rkhapre commented 7 years ago

I am using Oracle DB, i solved the problem by adding sprintf with double quotes. Closing this. Thanks