How to enter the first 100 characters of 200 in mysql

I have a field with varchar (100) in mysql, I want to save the first 100 characters, because my data length is 200 characters (ignore the last 100 characters). I do not want to change my source code. It is possible in MS-Access and MS Server, but I want to do it in mysql.

I apply this in java with hibernate, which means I am not writing code for input. Here I just use the save () method and drop the "Big Data".

I have an Exception -

Called: java.sql.BatchUpdateException: Data Truncation: Data for column "FBUrl" on row 1 is too long at com.mysql.jdbc.PreparedStatement.executeBatchSerially(PreparedStatement.java:1527) at com.mysql.jdbc.PreparedStatement.executeBatch(PreparedStatement.java:1065) at org.hibernate.jdbc.BatchingBatcher.doExecuteBatch(BatchingBatcher.java:58) at org.hibernate.jdbc.AbstractBatcher.executeBatch(AbstractBatcher.java:195) glb.chatmeter.exception.AdException: Could not Save Facebook page Data.

+3
source share
4 answers

: . , , .


substring:

INSERT INTO MyTable (Myfield) values (SUBSTRING('long string', 1, 100))

pos 1 ( ), , len , .

+6

SUBSTRING() :

INSERT INTO table (column) VALUES (SUBSTRING("your data...", 1, 100))
+2

SELECT INSERT('your string', 0, 100, '');

+1

, , - MySQL. , sql_mode:

, STRICT_TRANS_TABLES:

STRICT_TRANS_TABLES, MySQL . , MySQL . MySQL , . 10.1.4, " ".

, . , , , , , , DB.

0

All Articles