Connecting Tech Pros Worldwide Forums | Help | Site Map

Data truncation

Newbie
 
Join Date: Sep 2007
Posts: 1
#1: Sep 14 '07
i have a problem

com.mysql.jdbc.MysqlDataTruncation: Data truncation: Data truncated for column 'FGiroNPagDol' at row 1
at com.mysql.jdbc.SQLError.convertShowWarningsToSQLWa rnings(SQLError.java:717)
at com.mysql.jdbc.MysqlIO.scanForAndThrowDataTruncati on(MysqlIO.java:3183)
at com.mysql.jdbc.MysqlIO.sqlQueryDirect(MysqlIO.java :1874)
at com.mysql.jdbc.Connection.execSQL(Connection.java: 3256)
at com.mysql.jdbc.PreparedStatement.executeInternal(P reparedStatement.java:1313)
at com.mysql.jdbc.PreparedStatement.executeUpdate(Pre paredStatement.java:1585)
at com.mysql.jdbc.PreparedStatement.executeUpdate(Pre paredStatement.java:1500)
at com.mysql.jdbc.PreparedStatement.executeUpdate(Pre paredStatement.java:1485)
at packapp.Desempaquetar.grabarEnTablaGiros(Desempaqu etar.java:872)
at packapp.Operaciones.desempaquetar(Operaciones.java :333)
at packinterfaz.servletinterfaz.ProcesarArchivo.proce ssRequest(ProcesarArchivo.java:156)
at packinterfaz.servletinterfaz.ProcesarArchivo.doPos t(ProcesarArchivo.java:266)
at javax.servlet.http.HttpServlet.service(HttpServlet .java:710)
at javax.servlet.http.HttpServlet.service(HttpServlet .java:803)
at org.apache.catalina.core.ApplicationFilterChain.in ternalDoFilter(ApplicationFilterChain.java:269)
at org.apache.catalina.core.ApplicationFilterChain.do Filter(ApplicationFilterChain.java:188)
at org.apache.catalina.core.StandardWrapperValve.invo ke(StandardWrapperValve.java:210)
at org.apache.catalina.core.StandardContextValve.invo ke(StandardContextValve.java:174)
at org.apache.catalina.core.StandardHostValve.invoke( StandardHostValve.java:127)
at org.apache.catalina.valves.ErrorReportValve.invoke (ErrorReportValve.java:117)
at org.apache.catalina.core.StandardEngineValve.invok e(StandardEngineValve.java:108)
at org.apache.catalina.connector.CoyoteAdapter.servic e(CoyoteAdapter.java:151)
at org.apache.coyote.http11.Http11Processor.process(H ttp11Processor.java:870)
at org.apache.coyote.http11.Http11BaseProtocol$Http11 ConnectionHandler.processConnection(Http11BaseProt ocol.java:665)
at org.apache.tomcat.util.net.PoolTcpEndpoint.process Socket(PoolTcpEndpoint.java:528)
at org.apache.tomcat.util.net.LeaderFollowerWorkerThr ead.runIt(LeaderFollowerWorkerThread.java:81)
at org.apache.tomcat.util.threads.ThreadPool$ControlR unnable.run(ThreadPool.java:685)
at java.lang.Thread.run(Thread.java:595)
Error = Data truncation: Data truncated for column 'FGiroNPagDol' at row 1


please help me

Lives Here
 
Join Date: Sep 2006
Posts: 12,070
#2: Sep 15 '07

re: Data truncation


Could you show the sql that gave this exception?
JosAH's Avatar
Expert
 
Join Date: Mar 2007
Posts: 10,611
#3: Sep 15 '07

re: Data truncation


And also please show the type of column 'FGiroNPagDol' and the value you
wanted to store in it.

kind regards,

Jos
Newbie
 
Join Date: Oct 2007
Posts: 6
#4: Oct 16 '07

re: Data truncation


Hi,
I have the same problems when I try to convert data from *.dbf to MySQL table:

Exception in thread "main" com.mysql.jdbc.MysqlDataTruncation: Data truncation: Data truncated for column 'DATAPROD' at row 1
at com.mysql.jdbc.SQLError.convertShowWarningsToSQLWa rnings(SQLError.java:717)
at com.mysql.jdbc.MysqlIO.scanForAndThrowDataTruncati on(MysqlIO.java:3102)
at com.mysql.jdbc.MysqlIO.sqlQueryDirect(MysqlIO.java :1862)
at com.mysql.jdbc.Connection.execSQL(Connection.java: 3249)
at com.mysql.jdbc.PreparedStatement.executeInternal(P reparedStatement.java:1268)
at com.mysql.jdbc.PreparedStatement.executeUpdate(Pre paredStatement.java:1541)
at com.mysql.jdbc.PreparedStatement.executeUpdate(Pre paredStatement.java:1455)
at com.mysql.jdbc.PreparedStatement.executeUpdate(Pre paredStatement.java:1440)
at converting.ConvertData2.rewrite(ConvertData2.java: 231)
at startapp.StartClass.main(StartClass.java:26)

The type of 'DATAPROD' in *.dbf file is Date (like 02.02.2007) and it will be VARCHAR in MySQL.

Below I'm wrote the void when I'm insert data into MySQL table:

public static void rewrite() throws SQLException {
getConnect();
createStmt();
try {
ostr = new FileOutputStream(outputFolder + outputFile);
ostrw = new OutputStreamWriter(ostr, "UTF-8");
}
catch(IOException e) {
echonl("rewrite1 : " + e.getMessage() + e.toString() + outputFolder + outputFile );
}
Object []rowObjects;
echonl("counting");
rowCount = 0;
String strSQLIns = "";
strSQLIns += "insert into " + tablename + " (";
try {
try {
for(int j=0; j<fieldCount; j++) {
DBFField field = reader.getField( j);
strSQLIns += convertFieldName(field.getName()) ;
if (j != fieldCount - 1) {
strSQLIns += ",";
}
}
strSQLIns += ") values ";
while((rowObjects = reader.nextRecord()) != null) {
rowCount++;
if (rowCount == 1) {
ostrw.write(strSQLIns);
}
else {
if (rowCount % multiple_rows == 0) {
ostrw.write(";");
ostrw.write("\n");
ostrw.write(strSQLIns);
}
else {
if (rowCount > 1) {
ostrw.write(",");
}
}
}
if (rowCount % 20000 == 0) {
echo(Integer.toString(rowCount) + "..");
}
if (rowCount % 100000 == 0) {
echonl("");
}
pstmt = incon.prepareStatement(strSQLIns + insertRowStmt(rowObjects));
pstmt.executeUpdate();
//ostrw.write("\n");
//ostrw.write(insertRowStmt(rowObjects));
}
}
catch(DBFException e) {
echonl("rewrite-- : " + e.getMessage());
}
ostrw.close();
}
catch(IOException e) {
echonl("rewrite3 : " + e.getMessage() + "**" + e.toString() + outputFolder + outputFile);
}
}

P.S. In MySQL table put only one row and value in this column is "Wed May".
How I can solve this problem?
Lives Here
 
Join Date: Sep 2006
Posts: 12,070
#5: Oct 16 '07

re: Data truncation


Quote:

Originally Posted by JavaJunior

Hi,
I have the same problems when I try to convert data from *.dbf to MySQL table:

Exception in thread "main" com.mysql.jdbc.MysqlDataTruncation: Data truncation: Data truncated for column 'DATAPROD' at row 1
at com.mysql.jdbc.SQLError.convertShowWarningsToSQLWa rnings(SQLError.java:717)
at com.mysql.jdbc.MysqlIO.scanForAndThrowDataTruncati on(MysqlIO.java:3102)
at com.mysql.jdbc.MysqlIO.sqlQueryDirect(MysqlIO.java :1862)
at com.mysql.jdbc.Connection.execSQL(Connection.java: 3249)
at com.mysql.jdbc.PreparedStatement.executeInternal(P reparedStatement.java:1268)
at com.mysql.jdbc.PreparedStatement.executeUpdate(Pre paredStatement.java:1541)
at com.mysql.jdbc.PreparedStatement.executeUpdate(Pre paredStatement.java:1455)
at com.mysql.jdbc.PreparedStatement.executeUpdate(Pre paredStatement.java:1440)
at converting.ConvertData2.rewrite(ConvertData2.java: 231)
at startapp.StartClass.main(StartClass.java:26)

The type of 'DATAPROD' in *.dbf file is Date (like 02.02.2007) and it will be VARCHAR in MySQL.

Below I'm wrote the void when I'm insert data into MySQL table:

public static void rewrite() throws SQLException {
getConnect();
createStmt();
try {
ostr = new FileOutputStream(outputFolder + outputFile);
ostrw = new OutputStreamWriter(ostr, "UTF-8");
}
catch(IOException e) {
echonl("rewrite1 : " + e.getMessage() + e.toString() + outputFolder + outputFile );
}
Object []rowObjects;
echonl("counting");
rowCount = 0;
String strSQLIns = "";
strSQLIns += "insert into " + tablename + " (";
try {
try {
for(int j=0; j<fieldCount; j++) {
DBFField field = reader.getField( j);
strSQLIns += convertFieldName(field.getName()) ;
if (j != fieldCount - 1) {
strSQLIns += ",";
}
}
strSQLIns += ") values ";
while((rowObjects = reader.nextRecord()) != null) {
rowCount++;
if (rowCount == 1) {
ostrw.write(strSQLIns);
}
else {
if (rowCount % multiple_rows == 0) {
ostrw.write(";");
ostrw.write("\n");
ostrw.write(strSQLIns);
}
else {
if (rowCount > 1) {
ostrw.write(",");
}
}
}
if (rowCount % 20000 == 0) {
echo(Integer.toString(rowCount) + "..");
}
if (rowCount % 100000 == 0) {
echonl("");
}
pstmt = incon.prepareStatement(strSQLIns + insertRowStmt(rowObjects));
pstmt.executeUpdate();
//ostrw.write("\n");
//ostrw.write(insertRowStmt(rowObjects));
}
}
catch(DBFException e) {
echonl("rewrite-- : " + e.getMessage());
}
ostrw.close();
}
catch(IOException e) {
echonl("rewrite3 : " + e.getMessage() + "**" + e.toString() + outputFolder + outputFile);
}
}

P.S. In MySQL table put only one row and value in this column is "Wed May".
How I can solve this problem?

Post the sql statement that was executed (Capture it by System.out.println before the query was executed).
Also state your MySQL version.
Newbie
 
Join Date: Oct 2007
Posts: 6
#6: Oct 16 '07

re: Data truncation


Quote:

Originally Posted by r035198x

Post the sql statement that was executed (Capture it by System.out.println before the query was executed).
Also state your MySQL version.

MySQL version is 4.1.
SQL statement is:
insert into ALEX (DATATIME,DOCTYPE,DOCNUM,STRNUM,KODNOMEN,NOMENKLAT ,EDIZM,DATAPROD,KOLVO,VES,CENA,SEBEST,KODKLIENTA,K LIENT,FILIAL) values ('02.05.07 08:45:15','Нов яР сход* яН кл д* я','7063','1','00048','‘кумбрия тл.х/к б/г из сырья 400-600','кг','Wed May 02 00:00:00 MSD 2007','12.9','12.9','132.3','1150.94','00001306',' „емья*ов Н.П.','€лексеевк ')
Lives Here
 
Join Date: Sep 2006
Posts: 12,070
#7: Oct 16 '07

re: Data truncation


Quote:

Originally Posted by JavaJunior

MySQL version is 4.1.
SQL statement is:
insert into ALEX (DATATIME,DOCTYPE,DOCNUM,STRNUM,KODNOMEN,NOMENKLAT ,EDIZM,DATAPROD,KOLVO,VES,CENA,SEBEST,KODKLIENTA,K LIENT,FILIAL) values ('02.05.07 08:45:15','Нов яР сход* яН кл д* я','7063','1','00048','Скумбрия тл.х/к б/г из сырья 400-600','кг','Wed May 02 00:00:00 MSD 2007','12.9','12.9','132.3','1150.94','00001306',' Демья*ов Н.П.','Алексеевк ')

Most likely you are inserting a value wider than is allowed by your column. What's the type of the DATAPROD column and which value are you trying to put into it.
Newbie
 
Join Date: Oct 2007
Posts: 6
#8: Oct 16 '07

re: Data truncation


Quote:

Originally Posted by r035198x

Most likely you are inserting a value wider than is allowed by your column. What's the type of the DATAPROD column and which value are you trying to put into it.

The type of 'DATAPROD' in *.dbf file is Date (like 02.02.2007) and it will be VARCHAR in MySQL
Lives Here
 
Join Date: Sep 2006
Posts: 12,070
#9: Oct 16 '07

re: Data truncation


Quote:

Originally Posted by JavaJunior

The type of 'DATAPROD' in *.dbf file is Date (like 02.02.2007) and it will be VARCHAR in MySQL

Why don't you convert to Varchar first using TO_CHAR
Newbie
 
Join Date: Oct 2007
Posts: 6
#10: Oct 16 '07

re: Data truncation


Quote:

Originally Posted by r035198x

Why don't you convert to Varchar first using TO_CHAR

What do you mean "using TO_CHAR" - make field CHAR type, or something else?

I think the problem is in converting DBase type "Date" into MySQL type "Datetime". And another one problem in converting russian letters from *.dbf into MySQL table. I create mysql table with DEFAULT CHARSET=utf8.
Lives Here
 
Join Date: Sep 2006
Posts: 12,070
#11: Oct 16 '07

re: Data truncation


Quote:

Originally Posted by JavaJunior

What do you mean "using TO_CHAR" - make field CHAR type, or something else?

I think the problem is in converting DBase type "Date" into MySQL type "Datetime". And another one problem in converting russian letters from *.dbf into MySQL table. I create mysql table with DEFAULT CHARSET=utf8.

I thought you said the MySQL type is Varchar. Now you say it's DateTime?
Newbie
 
Join Date: Oct 2007
Posts: 6
#12: Oct 16 '07

re: Data truncation


Quote:

Originally Posted by r035198x

I thought you said the MySQL type is Varchar. Now you say it's DateTime?

sorry, I mean data in DATAPROD column in mysql table look like datetime: 'Wed May 02 00:00:00 MSD 2007', but it type is varchar.
Newbie
 
Join Date: Oct 2007
Posts: 6
#13: Oct 18 '07

re: Data truncation


It was easier than I think!
Field "DATAPROD" is dbf has only 8 symbols length. I set 50 symbols for this field and it works!

Now I have another problem with cyrillic encoding. )
Reply