Current Environment:
Database: Oracle 9i
Database field type: varchar2 (4000)
Input Chinese characters: more than 1000 characters
Cause:
My database character set should be UTF-8, for some character sets in UTF-8 or Europe, Oracle requires 2 or 3 bytes of storage space for a character during storage, although the table is defined as varchar2 (4000), The data_length of this field is two or three times the length. In this case, Oracle will treat data_length over 4000 as long. Your table has two such fields. when inserting data, it is equivalent to operating two long fields at the same time, so an error is returned.
Solution: reduce the field length or split it. You can use the clob field type instead.
Current Environment:
Development Framework: Spring 2.0.6 + hibernate 3.2 data preview: Oracle 9i
Database field type: clob
Input words: 1000 ~ 2000
Current problems:Now I use the clob field type, but I have encountered this problem. When I insert or update the clob field in the Oracle database, the background shows java. SQL. sqlexception: ORA-01461: Can only assign a value to the long value inserted into the long column. This error occurs when the length of the inserted data is less than 1000 characters or more than 2000 characters. The length of the inserted data is between 1000 and characters ~ It takes 2000 of the time. After Google, ORA-01461 was a typical issue, and some people thought it was the issue of the clob field itself.Solution:
Method 1:
Use the latest Oracle 10g ojdbc14.jar driver to replace the original license.However, this method does not take effect.
Method 2:
1. The data member type in the hibernate object is string, and the ing database field type isOrg. springframework. Orm. hibernate. Support. clobstringtype. For example, @ suppresswarnings ("serial ")
@ Entity
@ Table (name
= "Guide ")
// @ Cache (usage = cacheconcurrencystrategy. read_write)
Public
Class Guide
{
@ Type (Type
= "Org. springframework. Orm. hibernate3.support. clobstringtype ")
Private string content;
// Content
// Get & set
}
2. If the clob type of spring is used, inject the oraclelobhandler bean into the sessionfactory bean in applicationcontext. xml. The lobhandler configuration of ORACLE data volume is given below :.
<Bean
Id = "oraclelobhandler"
Class = "org. springframework. JDBC. Support. lob. extends lelobhandler"
Lazy-init = "true">
<Property
Name = "nativejdbcextractor" ref = "nativejdbcextractor"
/>
</Bean>
<Bean
Id = "nativejdbcextractor" class = "org. springframework. JDBC. Support. nativejdbc. commonsdbcpnativejdbcextractor"
Lazy-init = "true"
/>
<! -- Hibernate sessionfactory
-->
<Bean
Id = "sessionfactory" class = "org. springframework. Orm. hibernate3.annotation. annotationsessionfactorybean">
<Property
Name = "datasource" ref = "datasource"
/>
<Property
Name = "configlocation" value = "classpath: hibernate/hibernate. cfg. xml"
/>
<Property
Name = "hibernateproperties">
<Value>
</Value>
</Property>
<Property
Name = "lobhandler" ref = "oraclelobhandler"
/>
</Bean>
.
Lobhandler needs to access the local JDBC object. This task is entrusted to nativejdbcextractor bean. nativejdbcextractor is a local JDBC object Extraction Tool. Therefore, we inject a nativejdbcextractor into lobhandler. Finally, we inject the lobhandler bean into the sessionfactory bean that requires lob data access or directly into the DaO bean.
You may have noticed that both nativejdbcextractor and oraclelobhandler bean are set to lazy-init = "true", because nativejdbcextractor needs to obtain the underlying JDBC object through the runtime reflection mechanism, therefore, we need to avoid instantiating the two beans when the spring container starts. If the underlying data volume is another non-Oracle Data Volume such as DB2, SQL Server, and MySQL, simply configure a defaultlobhandler, as shown below: <Bean
Id = "defaultlobhandler"
Class = "org. springframework. JDBC. Support. lob. defaultlobhandler"
Lazy-init = "true"/>
<Bean
Id = "testdao" class = "com. Test. Dao. JDBC. testjdbcdao">
<Property name = "lobhandler" ref = "defaultlobhandler"/>
<Property
Name = "jdbctemplate" ref = "jdbctemplate"
/>
</Bean>
Defaultlobhandler simply acts as the proxy for standard JDBC preparedstatement and resultset objects. Because it does not need to access the local JDBC object of the database driver, it does not need the help of nativejdbcextractor. Using the second method can solve the problem I encountered, if you see "ORA-01461: Can only assign a value for the long value inserted into the long column, hope this method can help you easily take the ORA-01461.
PS: Provides Solutions for large-capacity Field Types in Oracle.
Long:Variable-length string data with a maximum length of 2 GB. Long has the feature of varchar2 columns. It can store up to one long column in a long table.
Long raw: Variable Length binary data, up to 2 GB
Clob: The character big object clob is used to store single-byte character data
Nclob: Used to store multi-byte character data
Blob: Used to store binary data
Bfile: Binary data stored in the file. The data in this file can only be read-only. However, this file is not included in the database. The bfile field is actually stored in the file system. The field stores the file positioning pointer. bfile is read-only for Oracle and does not participate in transactional control and data recovery.
Among them, clob, nclob, and blob are all internal lob (large object) types, with a maximum length of 4 GB. There is no long limit and only one column is allowed. Which data type is the best choice for saving images, text files, and Word files? Blob is the best. Long raw is also good, but long is the type to be discarded by Oracle. Therefore, blob is recommended.