Hi all,
I am changing over from fastinsert to datainsert and I am having an issue inserting blank spaces to my SQL table.
Ex: a = {''};
Old code (works): fastinsert(conn,tableName,fieldNames,a);
New code (doesn't work): datainsert(conn,tableName,fieldNames,a);
datainsert treats the blank character as empty, and inserts a NULL value to the table. Is there a way to force it to intrepret this as a blank character instead?
Thanks!

 채택된 답변

Madhav Rajan
Madhav Rajan 2015년 7월 21일

0 개 추천

I understand that you are trying to insert a black space into an SQL table using the "datainsert" function.
The "datainsert" function automatically casts the string '' which is of type MATLAB 'char' to NULL prior to the insertion. One workaround for this issue is to use the string representation in Java as shown in the following example:
Suppose I have a MYSQL table called "names" with three fields 'id', 'name' and 'subject'. I want to insert a record with the 'name' column's value to be '' (the empty string), I would do the following:
>> colnames = {'id','name' , 'subject'};
>> data = {13, java.lang.String(''),'asd'};
>> datainsert(conn,tablenames,colnames,data)
Hope I have answered your question.

댓글 수: 1

john
john 2015년 7월 22일
AWESOME! This worked and was exactly what I was looking for. Using this I was able to dramatically improve the performance of my code, thanks!

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

도움말 센터File Exchange에서 Particle & Nuclear Physics에 대해 자세히 알아보기

질문:

2015년 7월 15일

댓글:

2015년 7월 22일

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by