Several questions about developing Java under Oracle

zhaozj2021-02-16  64

Several questions about developing Java under Oracle

Author: super rookie [2002-05-27] return | Off

I have no longer want to write some articles similar to the tutorial, because since the tutorial is to have a history of history, and for my rookie-level programming, I only like to communicate some of my own experiences with my heart. It can not be a way, unrelated effects I want to say where. But some questions I can't tell it, because there are currently many "tutorials" on the online "tutorial" to lead the beginners, some are the errors of the author, some authors have never been developed, but they can write a one Software development articles. They only do translate, copy, cut, the easiest example is that the method of introducing large objects (files) stored in the Sun's JDK development document is wrong, but after N (n> 100) times No one is corrected, because the later people are just Copy, they don't really do it, just replace the original author into their own name. (Respect statement: An article signed by Axman, Super Rock, and Shi Sheng Sheng Sheng Sheng Sheng Sign In 2011

Question 1: If you load the JDBC driver: Normal we load the driver has three ways: 1) Class.Forname (String) This wants to initialize the driver's static content when the ClassLoad is specified, initialize the static content of the driver when loading In fact, the driver class calls DriverManager.RegisterDriver (driver); method 2) Use the system properties: system.getProperty (). Load (New fileInputStream); specify jdbc.driver = in the properties file The benefit of drivername is that multiple JDBCs can simultaneously load multiple JDBCs. When you change the database, you don't have to access Java source code, just modify the properties file 3) The most reliable regiver (Driver) is the most reliable, which can be used in any environment.

1) Simple method, but the JVM of MS cannot initialize correctly. For example, when using IE, you cannot use it in the applet. But 3) The method is not as good as 2) in flexibility, and can be considered according to the environment.

Question 2: Big object storage In general, large object storage is in the database to the database, of course, the large string in memory. For documents such as pictures, it is of course used in binary storage. There are many misunderstandings. The tutorial on the network is not in, even Sun own documents have been wrong, although the mistakes are small. According to the binary, it should be stored as a BLOB type, but JBDC2 cannot be directly stored in binary files. If you do this, you will get an IO instead of SQL anomaly, spend this, I spent nearly two hours. If you want to store a two-form file into Oracle, you will use long row type with a standard JDBC: create Table Tb_File (Name Varchar (20), Detail Long Row; then File File = New File ("AAA.gif" ); int fileLength = (int) file.length (); InputStream fin = new FileInputStream (file); PreparedStatement pstmt = con.prepareStatement ( "insert into tb_file values ​​( 'aaa.gif' ,?)"); pstmt.setBinaryStream (1, FIN, FileLength); pstmt.executeUpdate (); If you must use blob storage, you must use Oracle's own way: create table tb_file (Name Varchar (20), detail blob); con.setautocommit (False ); stmt.executeUpdate ("IAA.GIF ', EMPTY_BLOB ()") ")") ")") ")") ")"); below must be SELECT to get blob object again Write: rs = stmt.executeQuery ("SELECT DETAIL from TB_File WHERE NAME = 'aaa.gif' for upfdate "); if (rs.next ()) {blob blob = rs.getblob (1); binaryoutputstream out = (Oracle.sql.blob) blob) .GetbinaryoutputStream (); byte [ ] B = New Byte [(ORACLE.SQL.BLOB) BLOB .getBuffersize]; InputStream Fin = New FileInputStream (file); int LEN = 0; while ((len = fin.read (b))! = -1 ) Out.write (b, 0, len); fin.close (); out.close (); con enchart () ;con.commit ();

Also reading data, you can't be like long row, INPUTSTREAM IN = RS.GetBinaryInputStream ("Detail"); to blob blob = rs.getblob ("detail"); in = blob.getbinaryStream ();

转载请注明原文地址:https://www.9cbs.com/read-17311.html

New Post(0)