Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Inserts into databases (H2, Oracle) using templates fails when special characters(') is present in data #8

Open
anandbalaraman opened this issue Sep 7, 2017 · 2 comments

Comments

@anandbalaraman
Copy link

When a special character such as ' is present in the data, and when I load the data using AnyDataToDbDataTransferBuilder() withTargetSqlTemplate(), program fails.
We need to escape the special characters (by adding an extra ') while the template is transformed into actual values.
In my case, I read a binary file, form template and load data into H2 database.

@qamatic
Copy link
Owner

qamatic commented Sep 25, 2017

you need to subclass BinaryFileReader and override a method called createRowInstance and inject your own version of Row or subclass InMemory Row there. For example if you have your customRow extends from InMemory Row then you can override it in BinaryFileReader class.

`
public class MyRow extends InMemoryRow{
@OverRide
public Object getValue(int columnIndex){
//// do check for your column and data type and escape the string accordingly here
}
}

public class MyBinaryFileReader extends BinaryFileReader{
public Row createRowInstance(){
return MyRow();
}
}

//use MyBinaryFileReader in AnyDataToDbDataTransferBuilder instead of BinaryFileReader
`

@anandbalaraman
Copy link
Author

Handled the special character issue by overriding public Object getValue(int columnIndex) in my class EbcdicRow which extends InMemoryRow did the job. Thanks for the suggestion.

@qamatic qamatic closed this as completed Oct 13, 2017
@qamatic qamatic reopened this Oct 13, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants