Problems with JSP and Oracle are encountered
(1) Write stored procedures in Oracle and read in Java find it is impossible to get a long type with getstring. and other varchar2 taken out together can be taken out as string values
String content=rs.getstring ("content"); No value to display null
Ask what you can do to remove the long type value and display it in a textarea.
(2) in the JSP I use the string type to get the textarea value and write it to a long field. This is doable.
Cstmt.setstring (9,content); Enter the Nineth long field and the content is a string.
But I don't know if this input will cause any damage to the input data.
Is there a better way to enter the textarea data into the long field of Oracle?
Code for inserting Long Data
public voidInsertData(string code, string name, string partner, String textfile) throws Exception {
Create a File to read data from the specified text File (textfile) File File = New File (GetClass (). getClassLoader (). GetResource (Textfile). GetFile ());
Prepare the statement for inserting a row into the Otn_airlines_long PreparedStatement pstmt = connection.preparestatement ("INSERT into" + "Otn_airlines_long (code, name, partner," + "Airline_insurance_data) VALUES (?,?,?,?)");
Bind the parameter values for the above statement Pstmt.setstring (1, code); Pstmt.setstring (2, name); Pstmt.setstring (3, partner);
Bind the Airline_insurance_data column to a input Ascii stream that Returns the ASCII data to is inserted into the Longraw column Pstmt.setcharacterstream (4, new FileReader (file), (int) file.length ());
Execute the statement Pstmt.execute (); } } ................ ................ |
Code for retrieving Long Data
public voidDisplaylongdata(String code) { ........ ........ Create a PreparedStatement object to execute the QUERY PreparedStatement PST = Connection.preparestatement ("Select Airline_insurance_data" + "From Otn_airlines_long WHERE code =?");
Bind the airline code to the query Pst.setstring (1, code); Gui.putstatus ("Reading Long Column from the DB, please wait ...");
Excute the Query ResultSet ResultSet = Pst.executequery ();
Populate the ResultSet while (Resultset.next ()) { InputStream Insurancedata; Holds the LONG data StringBuffer DataBuffer = new StringBuffer (); /* Obtain the LONG data into a byte array. LONG data can is accessed in Two ways:1) by retrieving all the "data in one Shot" (GetBytes method) 2) by using streams. The LONG data is made available to the program As an Ascii or Unicode stream, and the data can is retrieved chunk by Chunk, which is more eficient in terms of memory In this sample we illustrate retrieval using streams */ insurancedata = Resultset.getasciistream (1); while ((chunk = Insurancedata.read ())!=-1) { Databuffer.append ((char) chunk); } ................ ................ |