I have been using ORACLE9i and Oracle8 for a long time. I have written down the issues that need attention when using JSP here for your reference only.
1. How to deal with large types of Clob and BLOB.
CLOB can be used to store large text data, and can store up to 4GB of data. It is relatively common in application development. The sql.Clob class provided by Java corresponds to it. It provides two methods to read Get the data of Clob:
The getCharacterStream() method returns the unicode-encoded input stream (java.io.Reader object).
The getAsciiStream() method returns the ASCII-encoded input stream (java.io.InputStream object).
So if you have If you may store Chinese characters, you must use the previous method.
Now give a practical example and let me learn how to use CLOB step by step.
First, create a table with CLOB fields:
create table test (id INTEGER, content clob);
Next, we insert a record into this table through JSP, and then get and display it.
Insertion operation:
The following points to note are:
1) Clob type data cannot be directly inserted, and must be given first through the empty_clob() method. It allocates a locator (in the same way, use the empty_blob() function to allocate a locator for blobs). Then select it (of course it has no data at this time, but the result set is not empty), get a Clob object, and modify the object's The content makes it meet our needs, and then the row record is updated through the update method.
2) When modifying a record containing lob type through select, the row must be locked (implemented through the for update keyword), otherwise Oracle will report an error.
3) Just If the inserted record is selected for update, a "reading order violation" error will occur. The solution is to set the automatic submission function to false, that is, automatic submission is not allowed, then commit it, and then select it. This is the above The function of the //* lines in this code.
Next, we will read the newly inserted record from the database and display it:
2. Encoding problem
Because the developers of JAVA are foreigners, their support for Chinese is not very good. Okay, this has caused a lot of headaches for many of us, which is what we are talking about about Chinese character encoding. I won’t go into detail about some Chinese character encoding specifications. I will mainly talk about how to connect to an Oracle database. Some small problems, but these small problems are very troublesome.
1. The Chinese question inserted into the database must be converted into encoding
2. The Chinese read from the database must be converted into encoding.
Let us look at an encoded JAVA code:
//ECov.java import java.io.UnsupportedEncodingException; public class ECov { public static String asc2gb(String asc){ String ret; if(asc==null)return asc; try{ ret=new String(asc.getBytes("ISO8859_1"),"GB2312"); } catch(UnsupportedEncodingException e){ ret=asc; } return ret; } public static String gb2asc(String gb){ String ret; if(gb==null)return gb; try{ ret=new String(gb.getBytes("GB2312"),"ISO8859_1"); } catch(UnsupportedEncodingException e){ ret=gb; } return ret; } public static int byte2int(byte b){ return ((-1)>>>>24)&b; } } |
In fact, the meaning of this code is to combine the two methods into one.
ECov.gb2asc(arg) should be used when inserting into the database, and ECov.asc2gb(arg) should be used when reading. The most critical point is that Oracle seems to only recognize the encoding of ISO8859_1 format (just my idea).
3. Some small details
1. It is setAutoCommit(true or false), which is the commonly used commit() function in sqlPlus. If you use true, do not use commit(), otherwise you will still use the commit() method.
2. The processing of date types is actually not as simple as setDate() and getDate() as imagined. There are big loopholes in the middle. You will find it a lot of fun if you debug it yourself.
3. It is best to use connection pool technology in the database. It is a good method to use a standard J2EE environment and simple JNDI technology.