The new data types introduced in the SQL3 standard are provided in JDBC 2.0, such as blob (Binary Large Object), CLOB (CHARACTER LARGE Object), Array Object, REF (Object Reference, Object Reference), and UDT (user-defined data type, Support for User-Defined Dattype. These new data types are combined, enabling database designers to create richer patterns and simplify processing and persistence of complex data.
For example, we have to insert the user's photos to the TBL_USER table, then you can use the stream to import the BLOB object into the database:
String SQL = "INTSERT INTO TBL_USER VALUES (?,?)";
PreparedStatement PSTMT = Con.PrepareStatement (SQL);
File File = New File ("C: /Images/photo.jpg");
FileInputStream FIS = New FileInputStream (file);
PSTMT.SetString (1, "john");
Pstmt.setBinaryStream (2, Fis, (int) file.length ());
PSTMT.ExecuteUpdate ();
PSTMT.Close ();
fis.close ();
Where the first parameter of the SQL statement is the username, the second parameter is Photo, which is a BLOB type object. This allows us to obtain the data with the program:
String SQL = "SELECT Photo from TBL_USER WHERE Username =?";
PreparedStatement PSTMT = Con.PrepareStatement (SELECTSQL);
PSTMT.SetString (1, "john");
ResultSet RS = pstmt.executeQuery ();
rs.next ();
BLOB BLOB = rs.getblob ("photo");
Imageicon icon = new imageicon (blob.getbytes (1, (int) blob.length ())));
Jlabel Photo = New Jlabel (icon);
Rs.close ();
PSTMT.Close ();
Similarly, we can also operate corresponding to the Clob object. Below is an example in inserting a Clob object into a database from the ASCII stream:
String SQL = "INSERT INTO TBL_ARTICLES VALUES (?,?)";
PreparedStatement PSTMT = Con.PrepareStatement (SQL);
File file = new file ("c: /data/news.txt");
FileInputStream FIS = New FileInputStream (file);
PSTMT.SetString (1, "Iraq War");
Pstmt.setasciistream (2, Fis, (int) file.Length ());
PSTMT.ExecuteUpdate ();
PSTMT.Close ();
fis.close ();
Similarly, we can also remove the Clob object from the database with a similar approach: string sql = "SELECT Content from TBL_Articles Where title =?";
PreparedStatement PSTMT = Con.PrepareStatement (SQL);
PSTMT.SetString (1, "Iraq War");
ResultSet RS = pstmt.executeQuery ();
rs.next ();
Clob Clob = rs.getClob ("Content");
InputStreamReader in = New InputStreamReader (Clob.Getasciistream ());
Jtextarea text = new jtextarea (ReadString (in));
Rs.close ();
PSTMT.Close ();
(T111)