Vijaya Seetharaman
Vijaya Seetharaman

Reputation: 181

Apache Flink: Exception when using JDBCOutputFormat

I implemented a Flink programm and tried to store the result DataSet into relational database. I did the following command:

data.output(JDBCOutputFormat.buildJDBCOutputFormat()
                    .setDBUrl(dbURL)
                    .setDrivername(drivername)
                    .setUsername(username)
                    .setPassword(password)
                    .finish()
                    );

dbUrl,drivername, username and password are separately stored in a String.

I get the following error:

The method output(OutputFormat<Tuple8<String,String,String,String,String,String,String,String>>) 
in the type DataSet<Tuple8<String,String,String,String,String,String,String,String>> 
is not applicable for the arguments (JDBCOutputFormat) 

How can I solve this problem?

Upvotes: 0

Views: 800

Answers (1)

avidlearner
avidlearner

Reputation: 253

From the error message, it looks like your DataSet is not of the type Row (org.apache.flink.types.Row). Convert it to Row type and then call the output function.

Example code to convert variable 'value' of Tuple2 type to Row.

Row obj = new Row(2);
obj.setField(0,value.f0);
obj.setField(1,value.f1);

Since your DataSet contains elements of Tuple8 type, your Row should be of size 8 (Row(8)). You can use a map function to transform each element from Tuple8 to Row.

Upvotes: 1

Related Questions