Tutorials to .com

Tutorials to .com » Jsp » Database » To deal with a complete example of blob

To deal with a complete example of blob

Print View , by: iSee ,Total views: 9 ,Word Count: 220 ,Date: Sun, 19 Apr 2009 Time: 1:37 AM

import oracle.jdbc.driver.OracleResultSet;
import oracle.sql.BLOB;

import java.sql.DriverManager;
import java.sql.Connection;
import java.sql.ResultSet;
import java.io. *;
import java.sql.Statement;
public class testBlob (
public static void main (String args []) (
try (
DriverManager.registerDriver (new oracle.jdbc.driver.OracleDriver ());
Connection conn = DriverManager.getConnection ( "jdbc: oracle: thin: @ java: 1521: eteda", "system", "manager");
conn.setAutoCommit (false);
Statement stmt = conn.createStatement ();
stmt.execute ( "insert into testblob values (empty_blob ())");
ResultSet rset = stmt.executeQuery ( "SELECT tt FROM testblob FOR UPDATE");
BLOB blob = null;
while (rset.next ()) (
blob = ((OracleResultSet) rset). getBLOB (1);
System.out.println (blob.length ());
)
File binaryFile = new File ( "c: \ \ meilin.xml");
System.out.println ( "meilin.xml length =" + binaryFile.length ());
FileInputStream instream = new FileInputStream (binaryFile);
OutputStream outstream = blob.getBinaryOutputStream ();
int chunk = blob.getChunkSize ();
System.out.println ( "chunk size =" + chunk);
byte [] buffer = new byte [chunk];
int length = -1;
while ((length = instream.read (buffer))! = -1)
outstream.write (buffer, 0, length);
instream.close ();
outstream.close ();
conn.commit ();

) Catch (Exception e) (
System.out.println (e.toString ());
)
)

)


Jsp And Database Articles


Can't Find What You're Looking For?


Rating: Not yet rated

Comments

No comments posted.