KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > dinamica > SaveBlob


1 package dinamica;
2
3 import java.io.*;
4
5 /**
6  * Generic transaction class that saves uploaded file
7  * into blob column in database table via JDBC prepared statements.
8  * The SQL will be preprocessed to set all
9  * the required static values, the BLOB data will
10  * be sent to the server using a prepared statement.<br>
11  * Plase consult the Dinamica BLOB How-to (cat-blob.pdf)
12  * to learn about required table structure and available
13  * blob management facilities. This class assumes that you are
14  * using the generic Upload component provided with Dinamica
15  * since v2.0.9 (look into /dinamica/extra folder).
16  *
17  * @author Martin Cordova
18  * */

19 public class SaveBlob extends GenericTableManager
20 {
21
22     /* (non-Javadoc)
23      * @see dinamica.GenericTransaction#service(dinamica.Recordset)
24      */

25     public int service(Recordset inputParams) throws Throwable JavaDoc
26     {
27         //reuse superclass code
28
int rc = super.service(inputParams);
29         
30         //get temp file
31
String JavaDoc path = (String JavaDoc)inputParams.getValue("file");
32         File f = new File(path);
33         
34         //get file size
35
Integer JavaDoc size = new Integer JavaDoc((int)f.length());
36         inputParams.setValue("image_size", size);
37
38         //prepare sql template (replace static values)
39
String JavaDoc sql = getResource("query.sql");
40         sql = getSQL(sql, inputParams);
41         
42         //get db object and save blob using prepared statement
43
Db db = getDb();
44         db.saveBlob(sql, path);
45         
46         //delete temp file
47
f.delete();
48         
49         return rc;
50         
51     }
52
53 }
54
Popular Tags