One problem: If Paul load JDBC driver:
We normally load the driver three ways:
1) Class.forName (String) that want to be on a String classLoader the class specified in the time of loading the static content of the driver are initialized, in fact, when the driver class called DriverManager.registerDriver (driver) method.
2) Use the system property: System.getProperty (). Load (new FileInputStream ("properties file")); in the properties file specified jdbc.driver = drivername such benefits can also load multiple JDBC, for databaseJAVA source code when you do not have access to only modify the properties file.
3) Direct registerDriver (driver) This method is most reliable in any environment.1) The method is simple, but MS's JVM can not correctly initialized.For example when using IE can not use the APPLET, should be 3) of the method.But 3) the method in flexibility as 2), based on comprehensive consideration of the environment.
Second problem: a large object store
In general, the large object storage is to save the file to the database, of course, the super string can be in memory.Such as image files for the course is to use binary storage, there are a lot of errors, 99% of tutorials on the network will not work, even the SUN own documents have been wrong, although the error is small.Ordinarily the binary file should be saved as a BLOB type, but not directly on the BLOB JBDC2 into a binary file, if you do not get a SQL exception IO, this took me nearly two hours to clear.
If you want the file system into a two-ORACLE, you should use the standard JDBC types with LONG ROW:
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 their own methods ORACLE:
create table tb_file (name varchar (20), detail BLOB);
con.setAutoCommit (false);
stmt.executeUpdate
("Insert into tb_file values ('aaa.gif', empty_blob ())");
SELECT BLOB must be below the object to write again:
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.commit ();}
Similarly, as you can not read data as LONG ROW
InputStream in = rs.getBinaryInputStream ("detail");
But to
Blob blob = rs.getBlob ("detail"); in = blob.getBinaryStream ();
Problem Three: You can scroll through the result set
ORACLE clearly do not support the result set rolling, then we get a scrollable JDBC result set is supported with the JDBC own, that is the result set to a high degree of cache in memory, many, many developers are mistakenly considered to be database supportThe.But they did not really check a lot of rows, query a large number of rows if it is yes, then should not it! For ultra large number of rows of data, rather stupid way to return to it and do not use the scroll result sets.