473,395 Members | 1,629 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

Data truncation: Data too long for column 'Phone' at row 1

I am inserting data into temp table in MYSQL database.I have given size of 'Phone' column as VARCHAR(20) and have inserted data of exactly 10 character and it is constant.

Here is my code:

Expand|Select|Wrap|Line Numbers
  1. java.sql.PreparedStatement insertStmt = null;
  2.  
  3.                  String insertQuery = "insert into "+tableName+"(";
  4.                  for(String col : columnList){
  5.                              insertQuery+=col+",";
  6.                          }
  7.                 insertQuery = insertQuery.substring(0,insertQuery.lastIndexOf(","));
  8.                          insertQuery+=") values (";
  9.                          for(String col : columnList){
  10.                              insertQuery+="?,";
  11.                          }
  12.                 insertQuery = insertQuery.substring(0,insertQuery.lastIndexOf(","));
  13.                             insertQuery+=")";
  14.                          insertStmt = mysqlConn.prepareStatement(insertQuery);
  15.  
  16.                 while(rs.next())
  17.                      {
  18.                     for(int j=1;j<=columnList.size();j++)
  19.                     {
  20.                         insertStmt.setString(j,rs.getString(j).trim());
  21.                         System.out.println(rs.getString(j).trim());
  22.                     }
  23.                     insertStmt.addBatch();
  24.                     i++;
  25.  
  26.                     }
  27.                 insertStmt.executeBatch();    
  28.  
  29.                 mysqlConn.setAutoCommit(true);
  30.                 rs = null;
and i am getting below error :

java.sql.BatchUpdateException: Data truncation: Data too long for column 'Phone' at row 1
Completed Temp tables 1&2
at com.mysql.jdbc.PreparedStatement.executeBatchSeria lly(PreparedStatement.java:1269)
at com.mysql.jdbc.PreparedStatement.executeBatch(Prep aredStatement.java:955)
at MultipleDataExtraction.addDataToTempTable(Multiple DataExtraction.java:132)
at MultipleDataExtraction.addDataToFinalTempTable(Mul tipleDataExtraction.java:94)


Please help..
Jul 11 '14 #1
1 2314
Rabbit
12,516 Expert Mod 8TB
And what does the SQL string show after you build it but before you run it?
Jul 11 '14 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

0
by: Sunil Menon | last post by:
Dear All, Problem: In Oracle database, we have a column of type LONG. We use .Net OLEDb technology for database access. For update we use OleDbParameter . But problem is, if LONG string size...
3
by: Bob Day | last post by:
VS 2003, sql How do you determine the data type of a column if its value is DBNull? 1)Table: Column1 STRING non-nullable 2) Fill to a DataSet via DataAdapter 3) dim Data_Type_Is...
5
by: yma | last post by:
Hello, I tried to display a column in MS Access 2000 nwind.mdb using 3 data controls. But I got "It is already opened exclusively by another user, or you need permission to view its data." I...
6
by: syvman | last post by:
Hi everyone... I am pulling my hair out trying to do this, and was wondering if someone could give me some assistance... I have an Excel spreadsheet containing several worksheets. I'd like to be...
3
by: nittin14 | last post by:
helo every1, pls solve my problem i m showing data in data list using asp.net 2003 My problem is FirstName // column name in datalist RAVI ANIL AMIT
12
by: Juan Carlos Espinoza | last post by:
i have a problem com.mysql.jdbc.MysqlDataTruncation: Data truncation: Data truncated for column 'FGiroNPagDol' at row 1 at...
1
by: anjanareddy | last post by:
Hai, i am unable to inserting duplicate data into UNIQUE index column, Is there any other process, to insert duplicate data into UNIQUE index column? plz let me know.. Thanks & Regards...
5
vijcbe
by: vijcbe | last post by:
Hello friends!! I have a question.. Let me have a table which consists the details of 5 employees, starting from employee id 1 to 5 as given below. emp_id fname ... .... address 1 ...
2
by: david | last post by:
I've noticed that the following compiles (as C) under both VS8 and gcc with no warnings, even though there's a possibility of data truncation from enum to unsigned char. It does generate a warning...
13
by: chromis | last post by:
Hi, I have a query which updates the projects table of my database, however when I try to run my query with blank values i get the following error: Data truncation: Data truncated for column...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.