Docjar: A Java Source and Docuemnt Enginecom.*    java.*    javax.*    org.*    all    new    plug-in

Quick Search    Search Deep

Source code: org/ydp/db/Database.java


1   /*Database section
2    * version 0.2
3    * @author Michelle Meyer
4    * @date April 22, 2001 
5    * @version 1.1.1.1.1
6   */
7   
8   package org.ydp.db;
9   
10  import java.sql.*;
11  import java.util.*;
12  import java.io.*;
13  import java.net.*;
14  
15  public class Database {
16      //Name of JDBC driver
17      static String driverName= "org.gjt.mm.mysql.Driver";
18  
19      //Specify JDBC connection to URL
20      static String connectionURL = "jdbc:mysql://172.16.12.249:3306/";
21      static String user = "guest";
22      static String pass = "guest";
23  
24      //Specify JDBC Connection object
25      static Connection con = null;
26  
27      //Specify JDBC Statement object
28      static Statement stmt = null;
29  
30      //Declare SQL statement
31      static String sqlStatement = new String();
32  
33      //Specify JDBC ResultSet object
34      static java.sql.ResultSet rs = null;
35  
36      static String db_name = "ydp";
37      private static Vector fields = null;
38  /**
39   * Class constructor specifying the name of the database
40   * 
41   * @param name string   name of table to be created
42   */
43  
44  public Database(String name)
45  {    //Load driver
46      try
47      {   Class.forName(driverName);
48    //System.out.println("Database driver " + driverName + " loaded");
49      }
50      catch(java.lang.ClassNotFoundException e) 
51      {   System.err.print("ClassNotFoundException: "); 
52    System.err.println(e.getMessage());
53      }
54  
55      db_name = name;
56      connect();
57      setup();
58  }
59  
60  public Database() {
61      try {   
62    Class.forName(driverName);
63    //System.out.println("Database driver " + driverName + " loaded");
64      }
65      catch(java.lang.ClassNotFoundException e) {
66         System.err.print("ClassNotFoundException: "); 
67    System.err.println(e.getMessage());
68      }
69      setup();
70  }
71      
72  private static void setup() {
73    fields = new Vector();
74    fields.insertElementAt("pict_filename", fields.size());
75    fields.insertElementAt("pict_url", fields.size());
76    fields.insertElementAt("thumb_filename", fields.size());
77    fields.insertElementAt( "place", fields.size());
78    fields.insertElementAt( "subject", fields.size());
79    fields.insertElementAt( "description", fields.size());
80    fields.insertElementAt( "equipment_manufacturer", fields.size());
81    fields.insertElementAt( "equipment_model", fields.size());
82    fields.insertElementAt( "software", fields.size());
83    fields.insertElementAt( "exposure_time", fields.size());
84    fields.insertElementAt( "lens_f_number", fields.size());
85    fields.insertElementAt( "max_aperture", fields.size());
86    fields.insertElementAt( "lens_focal_length", fields.size());
87    fields.insertElementAt( "date_taken", fields.size());
88    fields.insertElementAt( "date_digitized", fields.size());
89    fields.insertElementAt( "time_taken", fields.size());
90    fields.insertElementAt( "time_digitized", fields.size());
91    fields.insertElementAt( "width", fields.size());
92    fields.insertElementAt( "height", fields.size());
93    fields.insertElementAt( "iso_speed", fields.size());
94    fields.insertElementAt( "exposure_mm", fields.size());
95    fields.insertElementAt( "light_source", fields.size());
96    fields.insertElementAt( "flash", fields.size());
97    fields.insertElementAt( "color_space", fields.size());
98    fields.insertElementAt( "exposure_program", fields.size());
99  }
100 
101 public void setConnectionURL(String str) {
102     connectionURL = "jdbc:mysql://" + str + "/";
103 }
104 
105 public void setDBName(String str) {
106     db_name = str;
107 }
108 
109 public void setUser(String str) {
110     user = str;
111 }
112 
113 public void setPass(String str) {
114     pass = str;
115 }
116 
117 public void connect() {
118     try { 
119   con = java.sql.DriverManager.getConnection(connectionURL + db_name, user, pass);
120   //System.out.println("Connection to database '" + connectionURL + db_name + "' successfully opened");
121     }
122     catch (SQLException e) { 
123   System.out.println("Error: " + e);
124     }
125 }
126 
127 /**
128  * Composes and sends an SQL statement to create the database.
129  *
130  * @return success bool    returns true if function completes successfully; returns false if it does not.
131  *
132  * @throws SQLException    if SQL statement is created incorrectly
133  */
134 
135 public static boolean create()
136 { //System.out.println("in create!!");
137   boolean success = true;
138 
139   sqlStatement = "CREATE TABLE " + db_name + " (" +
140   "pict_filename CHAR(40) not null," +
141   "pict_url CHAR(128) not null," +
142   "thumb_filename CHAR(128) not null," +
143   "place CHAR(255)," +
144   "subject CHAR(255)," +
145   "description CHAR(255)," +
146   "equipment_manufacturer CHAR(20)," +
147   "equipment_model CHAR(20)," +
148   "software CHAR(20)," +
149   "exposure_time CHAR(20)," +
150   "lens_f_number CHAR(20)," +
151   "max_aperture CHAR(20)," +
152   "lens_focal_length CHAR(20)," +
153   "date_taken CHAR(12)," +
154   "date_digitized CHAR(12)," +
155   "time_taken CHAR(10)," +
156   "time_digitized CHAR(10)," +
157   "width CHAR(6)," +
158   "height CHAR(6)," +
159   "iso_speed CHAR(10)," +
160   "exposure_mm CHAR(10)," +
161   "light_source CHAR(10)," +
162   "flash CHAR(10)," +    
163   "color_space CHAR(10)," +
164   "exposure_program CHAR(10)," +
165   "Primary key(pict_url))";
166 
167   //For debugging purposes only
168   //System.out.println("SQL statement = " + sqlStatement);
169 
170   try
171   { stmt = con.createStatement();
172     stmt.execute(sqlStatement);
173   }
174   catch(SQLException e)
175   { //System.out.println(e);
176     //e.printStackTrace();
177     while((e = e.getNextException()) != null)
178     { //e.printStackTrace();
179       success = false;
180     }
181   }
182   return success;
183 }
184 
185 /**
186  * Composes and sends an SQL statement to insert items into the database
187  *
188  * @param values vector   contains values corresponding with the fields to be inserted
189  *
190  * @return success bool    returns true if function completes successfully; returns false if it does not.
191  *
192  * @throws SQLException    if SQL statement is created incorrectly
193  */
194 
195 public static boolean insert( Vector values)
196 { String thumb = new String();
197   sqlStatement = "INSERT into " + db_name + " values (";
198 
199   for(int k = 0; k < 2; k++)
200     sqlStatement = sqlStatement + "\"" + values.elementAt(k) + "\", ";
201 
202   //Checking to see if thumbnail exists.  If not, fill blank with "none"
203   thumb = (String)values.elementAt(2);
204   if(thumb == "")
205     thumb = "none";
206   sqlStatement = sqlStatement + "\"" + thumb + "\", ";     
207 
208   for(int k = 3; k < 24; k++)
209     sqlStatement = sqlStatement + "\"" + values.elementAt(k) + "\", ";
210   for(int k = 24; k < 25; k++)
211     sqlStatement = sqlStatement + "\"" + values.elementAt(k) + "\"";
212   sqlStatement = sqlStatement + ")";  
213 
214   //For debugging purposes only
215   //System.out.println("SQL statement = " + sqlStatement);
216 
217   try
218   { stmt = con.createStatement();
219     stmt.execute(sqlStatement);
220   }
221   catch(SQLException e)
222   { //e.printStackTrace();
223     //System.out.println("Exception in database inserting value");
224     while((e = e.getNextException()) != null)
225     { //e.printStackTrace();
226     }
227     return false;
228   }
229   return true;
230 } 
231 
232 /**
233  * Composes and sends an SQL statement to delete the file specified.
234  * 
235  * @param file string    the pict_url (primary key) of the record to be deleted.
236  *
237  * @return success bool    returns true if function completes successfully; returns false if it does not.
238  *
239  * @throws SQLException    if SQL statement is created incorrectly
240  */
241 
242 public static boolean delete(String file)
243 { boolean success = true;
244   sqlStatement = "DELETE from " + db_name + " where pict_url = \"" + file + "\"";
245 
246   //For debugging purposes only
247   //System.out.println("SQL statement = " + sqlStatement);
248 
249   try
250   { stmt = con.createStatement();
251     stmt.executeUpdate(sqlStatement);
252   }
253   catch(SQLException e)
254   { //e.printStackTrace();
255     while((e = e.getNextException()) != null)
256     { //e.printStackTrace();
257     }
258     success = false;
259   }
260   return success;
261 }
262 
263 /**
264  * Composes and sends an SQL statement to update record indicated by values[0] 
265  * 
266  * @param values vector    new values which correspond to fields being updated.  values[0] = pict_url to be updated
267  *
268  * @return success bool    returns true if function completes successfully; returns false if it does not.
269  *
270  * @throws SQLException    if SQL statement is created incorrectly
271  */
272 
273 public static boolean update(Vector values)
274 { 
275   sqlStatement = "UPDATE " + db_name + " SET ";
276   int i = fields.size();
277   for(int k = 0; k < i; k++)
278   { 
279     sqlStatement = sqlStatement + fields.elementAt(k) + " = \"" + values.elementAt(k) + "\"";
280     if(k < (i-1))
281         sqlStatement = sqlStatement + ", ";
282   }
283   
284   sqlStatement = sqlStatement + " WHERE pict_url = \"" + values.elementAt(1) + "\""; 
285 
286   //For debugging purposes only
287   //System.out.println("SQL statement = " + sqlStatement);
288   
289   try
290   { stmt = con.createStatement();
291     stmt.executeUpdate(sqlStatement);
292   }
293   catch(SQLException e)
294   { //e.printStackTrace();
295     while((e = e.getNextException()) != null)
296     { //e.printStackTrace();
297     }
298     return false;
299   }
300   return true;
301 }
302 
303 /**
304  * Composes and sends an SQL statement to  query the database
305  *
306  * @param offset    indicates the index nubmer of the first result to be returned.
307  * @param count     indicates how many results to be returned
308  * @param fields string     indicates which fields are to be queried.
309  * @param values string     indicates the values corresponding to the fields being queried.
310  *
311  * @return result vector    contains the pict_filename, pict_url, and thumb_filename of files that match the query.
312  *
313  * @throws SQLException    if SQL statement is created incorrectly
314  */
315 
316 public static Vector query(int offset, int count, Vector fields, Vector values)
317 { int j = fields.size();
318   boolean isString;
319   int i;
320   String theRest = new String("");
321   Vector result = new Vector();
322   Vector temp = new Vector();
323 
324   for(int k = 0; k < j; k++)
325   { theRest = theRest + fields.elementAt(k) + " LIKE \"%" + values.elementAt(k) + "%\"";
326     if(k < j-1)
327       theRest = theRest + " and ";
328   }
329       
330   sqlStatement = "SELECT pict_url FROM " + db_name + " WHERE " + theRest 
331     + " ORDER BY pict_filename";
332 
333   try
334   { stmt = con.createStatement();
335     rs = stmt.executeQuery(sqlStatement);
336     while(rs.next())
337     {  temp.addElement(rs.getString(1));
338     }
339   }
340   catch(SQLException e)
341   { //e.printStackTrace();
342     while((e = e.getNextException()) != null)
343     { //e.printStackTrace();
344     }
345     System.out.println("Error: " + e);
346   }
347 
348   sqlStatement = "SELECT pict_filename FROM " + db_name + " WHERE " + theRest 
349     + " ORDER BY pict_filename";
350 
351   try
352   { stmt = con.createStatement();
353     rs = stmt.executeQuery(sqlStatement);
354     while(rs.next())
355     {  temp.addElement(rs.getString(1));
356     }
357   }
358   catch(SQLException e)
359   { //e.printStackTrace();
360     while((e = e.getNextException()) != null)
361     { //e.printStackTrace();
362     }
363     System.out.println("Error: " + e);
364   }
365 
366   sqlStatement = "SELECT thumb_filename FROM " + db_name + " WHERE " + theRest 
367     + " ORDER BY pict_filename";
368 
369   try
370   { stmt = con.createStatement();
371     rs = stmt.executeQuery(sqlStatement);
372     while(rs.next())
373     {  temp.addElement(rs.getString(1));
374     }
375   }
376   catch(SQLException e)
377   { //e.printStackTrace();
378     while((e = e.getNextException()) != null)
379     { //e.printStackTrace();
380     }
381     System.out.println("Error: " + e);
382   }
383 
384   //Seting 1st element of result to be number of entries received
385   int theCount = temp.size() / 3;
386 
387   if (count + offset > theCount)
388     count = theCount - offset;
389 
390   result.addElement(new Integer(theCount));
391 
392   for(i = 0; i < count; i++)
393   { result.addElement(temp.elementAt(i + offset));
394     result.addElement(temp.elementAt(theCount + i + offset));
395     result.addElement(temp.elementAt(2 * theCount + i + offset));
396   }
397 
398   return result;
399 }  
400 
401 /**
402  * Composes an SQL statement to find all files beginning with letter.
403  *
404  * @param offset    indicates the index nubmer of the first result to be returned.
405  * @param count     indicates how many results to be returned
406  * @param letter char    indicates the beginning letter/number of the filenames to return
407  *
408  * @return result vector    contains the pict_filename, pict_url, and thumb_filename of files that begin with letter.
409  *
410  * @throws SQLException    if SQL statement is created incorrectly
411  */
412 
413 public static Vector browse(int offset, int count, char letter)
414 { int i;
415   Vector result = new Vector();
416   Vector temp = new Vector();
417 
418   sqlStatement = "SELECT pict_url FROM " + db_name + " WHERE pict_filename LIKE \""
419     + letter + "%\" ORDER BY pict_filename";
420 
421   try
422   { stmt = con.createStatement();
423     rs = stmt.executeQuery(sqlStatement);
424     while(rs.next())
425     {  temp.addElement(rs.getString(1));
426     }
427   }
428   catch(SQLException e)
429   { //e.printStackTrace();
430     while((e = e.getNextException()) != null)
431     { //e.printStackTrace();
432     }
433     System.out.println("Error: " + e);
434   }
435 
436   sqlStatement = "SELECT pict_filename FROM " + db_name + 
437     " WHERE pict_filename LIKE \"" + letter + "%\" ORDER BY pict_filename";
438 
439   try
440   { stmt = con.createStatement();
441     rs = stmt.executeQuery(sqlStatement);
442     while(rs.next())
443     {  temp.addElement(rs.getString(1));
444     }
445   }
446   catch(SQLException e)
447   { e.printStackTrace();
448     while((e = e.getNextException()) != null)
449     { e.printStackTrace();
450       System.out.println("Error: " + e);
451     }
452   }
453 
454   sqlStatement = "SELECT  thumb_filename FROM " + db_name + 
455     " WHERE pict_filename LIKE \"" + letter + "%\" ORDER BY pict_filename";
456 
457   try
458   { stmt = con.createStatement();
459     rs = stmt.executeQuery(sqlStatement);
460     while(rs.next())
461     {  temp.addElement(rs.getString(1));
462     }
463   }
464   catch(SQLException e)
465   { //e.printStackTrace();
466     while((e = e.getNextException()) != null)
467     { //e.printStackTrace();
468     }
469     System.out.println("Error: " + e);
470   }
471 
472   int theCount = temp.size() / 3;
473 
474   if (count + offset > theCount)
475     count = theCount - offset;
476 
477   //Seting 1st element of result to be number of entries received
478   result.addElement(new Integer(theCount));
479 
480   for(i = 0; i < count; i++)
481   { result.addElement(temp.elementAt(i + offset));
482     result.addElement(temp.elementAt(theCount + i + offset));
483     result.addElement(temp.elementAt(2 * theCount + i + offset));
484   }
485 
486   int x = result.size();
487   for (i = 0; i < x; i++)
488     System.out.println(result.elementAt(i));
489    
490   return result;
491 }
492 
493 /**
494  * Composes an SQL statement to find all fields relating to a particular filename.
495  *
496  * @param theURL string    containing the complete URL (primary key) of the record to retrieve information
497  *
498  * @return result vector    contains values that relate to the pict_url
499  *
500  * @throws SQLException    if SQL statement is created incorrectly
501  */
502 
503 public static Vector getInfo(String theURL)
504 { Vector result = new Vector();
505   String codeString = new String("");
506 
507   sqlStatement = "SELECT pict_filename FROM " + db_name + " WHERE pict_url = " + "\"" 
508     + theURL + "\"";
509   try
510   { stmt = con.createStatement();
511     rs = stmt.executeQuery(sqlStatement);
512     while(rs.next())
513     {  result.addElement(rs.getString(1));
514     }
515   }
516   catch(SQLException e)
517   { e.printStackTrace();
518     while((e = e.getNextException()) != null)
519     { e.printStackTrace();
520     }
521   }
522 
523   sqlStatement = "SELECT pict_url FROM " + db_name + " WHERE pict_url = " + "\"" 
524     + theURL + "\"";
525   try
526   { stmt = con.createStatement();
527     rs = stmt.executeQuery(sqlStatement);
528     while(rs.next())
529     {  result.addElement(rs.getString(1));
530     }
531   }
532   catch(SQLException e)
533   { //e.printStackTrace();
534     while((e = e.getNextException()) != null)
535     { //e.printStackTrace();
536     }
537   }
538 
539   sqlStatement = "SELECT thumb_filename FROM " + db_name + " WHERE pict_url = " + "\"" 
540     + theURL + "\"";
541   try
542   { stmt = con.createStatement();
543     rs = stmt.executeQuery(sqlStatement);
544     while(rs.next())
545     {  result.addElement(rs.getString(1));
546     }
547   }
548   catch(SQLException e)
549   { //e.printStackTrace();
550     while((e = e.getNextException()) != null)
551     { //e.printStackTrace();
552     }
553   }
554 
555   sqlStatement = "SELECT place FROM " + db_name + " WHERE pict_url = " + "\"" 
556     + theURL + "\"";
557   try
558   { stmt = con.createStatement();
559     rs = stmt.executeQuery(sqlStatement);
560     while(rs.next())
561     {  result.addElement(rs.getString(1));
562     }
563   }
564   catch(SQLException e)
565   { //e.printStackTrace();
566     while((e = e.getNextException()) != null)
567     { //e.printStackTrace();
568     }
569   }
570 
571   sqlStatement = "SELECT subject FROM " + db_name + " WHERE pict_url = " + "\"" 
572     + theURL + "\"";
573   try
574   { stmt = con.createStatement();
575     rs = stmt.executeQuery(sqlStatement);
576     while(rs.next())
577     {  result.addElement(rs.getString(1));
578     }
579   }
580   catch(SQLException e)
581   { //e.printStackTrace();
582     while((e = e.getNextException()) != null)
583     { //e.printStackTrace();
584     }
585   }
586 
587   sqlStatement = "SELECT description FROM " + db_name + " WHERE pict_url = " + "\"" 
588     + theURL + "\"";
589   try
590   { stmt = con.createStatement();
591     rs = stmt.executeQuery(sqlStatement);
592     while(rs.next())
593     {  result.addElement(rs.getString(1));
594     }
595   }
596   catch(SQLException e)
597   { //e.printStackTrace();
598     while((e = e.getNextException()) != null)
599     { //e.printStackTrace();
600     }
601   }
602 
603   sqlStatement = "SELECT equipment_manufacturer FROM " + db_name + " WHERE pict_url = " + "\"" 
604     + theURL + "\"";
605   try
606   { stmt = con.createStatement();
607     rs = stmt.executeQuery(sqlStatement);
608     while(rs.next())
609     {  result.addElement(rs.getString(1));
610     }
611   }
612   catch(SQLException e)
613   { //e.printStackTrace();
614     while((e = e.getNextException()) != null)
615     { //e.printStackTrace();
616     }
617   }
618 
619   sqlStatement = "SELECT equipment_model FROM " + db_name + " WHERE pict_url = " + "\"" 
620     + theURL + "\"";
621   try
622   { stmt = con.createStatement();
623     rs = stmt.executeQuery(sqlStatement);
624     while(rs.next())
625     {  result.addElement(rs.getString(1));
626     }
627   }
628   catch(SQLException e)
629   { //e.printStackTrace();
630     while((e = e.getNextException()) != null)
631     { //e.printStackTrace();
632     }
633   }
634 
635   sqlStatement = "SELECT software FROM " + db_name + " WHERE pict_url = " + "\"" 
636     + theURL + "\"";
637   try
638   { stmt = con.createStatement();
639     rs = stmt.executeQuery(sqlStatement);
640     while(rs.next())
641     {  result.addElement(rs.getString(1));
642     }
643   }
644   catch(SQLException e)
645   { //e.printStackTrace();
646     while((e = e.getNextException()) != null)
647     { //e.printStackTrace();
648     }
649   }
650 
651   sqlStatement = "SELECT exposure_time FROM " + db_name + " WHERE pict_url = " + "\"" 
652     + theURL + "\"";
653   try
654   { stmt = con.createStatement();
655     rs = stmt.executeQuery(sqlStatement);
656     while(rs.next())
657     {  result.addElement(rs.getString(1));
658     }
659   }
660   catch(SQLException e)
661   { //e.printStackTrace();
662     while((e = e.getNextException()) != null)
663     { //e.printStackTrace();
664     }
665   }
666 
667   sqlStatement = "SELECT lens_f_number FROM " + db_name + " WHERE pict_url = " + "\"" 
668     + theURL + "\"";
669   try
670   { stmt = con.createStatement();
671     rs = stmt.executeQuery(sqlStatement);
672     while(rs.next())
673     {  result.addElement(rs.getString(1));
674     }
675   }
676   catch(SQLException e)
677   { //e.printStackTrace();
678     while((e = e.getNextException()) != null)
679     { //e.printStackTrace();
680     }
681   }
682 
683   sqlStatement = "SELECT max_aperture FROM " + db_name + " WHERE pict_url = " + "\"" 
684     + theURL + "\"";
685   try
686   { stmt = con.createStatement();
687     rs = stmt.executeQuery(sqlStatement);
688     while(rs.next())
689     {  result.addElement(rs.getString(1));
690     }
691   }
692   catch(SQLException e)
693   { //e.printStackTrace();
694     while((e = e.getNextException()) != null)
695     { //e.printStackTrace();
696     }
697   }
698 
699   sqlStatement = "SELECT lens_focal_length FROM " + db_name + " WHERE pict_url = " + "\"" 
700     + theURL + "\"";
701   try
702   { stmt = con.createStatement();
703     rs = stmt.executeQuery(sqlStatement);
704     while(rs.next())
705     {  result.addElement(rs.getString(1));
706     }
707   }
708   catch(SQLException e)
709   { //e.printStackTrace();
710     while((e = e.getNextException()) != null)
711     { //e.printStackTrace();
712     }
713   }
714 
715   sqlStatement = "SELECT date_taken FROM " + db_name + " WHERE pict_url = " + "\"" 
716     + theURL + "\"";
717   try
718   { stmt = con.createStatement();
719     rs = stmt.executeQuery(sqlStatement);
720     while(rs.next())
721     {  result.addElement(rs.getString(1));
722     }
723   }
724   catch(SQLException e)
725   { //e.printStackTrace();
726     while((e = e.getNextException()) != null)
727     { //e.printStackTrace();
728     }
729   }
730 
731   sqlStatement = "SELECT date_digitized FROM " + db_name + " WHERE pict_url = " + "\"" 
732     + theURL + "\"";
733   try
734   { stmt = con.createStatement();
735     rs = stmt.executeQuery(sqlStatement);
736     while(rs.next())
737     {  result.addElement(rs.getString(1));
738     }
739   }
740   catch(SQLException e)
741   { //e.printStackTrace();
742     while((e = e.getNextException()) != null)
743     { //e.printStackTrace();
744     }
745   }
746 
747   sqlStatement = "SELECT time_taken FROM " + db_name + " WHERE pict_url = " + "\"" 
748     + theURL + "\"";
749   try
750   { stmt = con.createStatement();
751     rs = stmt.executeQuery(sqlStatement);
752     while(rs.next())
753     {  result.addElement(rs.getString(1));
754     }
755   }
756   catch(SQLException e)
757   { //e.printStackTrace();
758     while((e = e.getNextException()) != null)
759     { //e.printStackTrace();
760     }
761   }
762 
763   sqlStatement = "SELECT time_digitized FROM " + db_name + " WHERE pict_url = " + "\"" 
764     + theURL + "\"";
765   try
766   { stmt = con.createStatement();
767     rs = stmt.executeQuery(sqlStatement);
768     while(rs.next())
769     {  result.addElement(rs.getString(1));
770     }
771   }
772   catch(SQLException e)
773   { //e.printStackTrace();
774     while((e = e.getNextException()) != null)
775     { //e.printStackTrace();
776     }
777   }
778 
779   sqlStatement = "SELECT width FROM " + db_name + " WHERE pict_url = " + "\"" 
780     + theURL + "\"";
781   try
782   { stmt = con.createStatement();
783     rs = stmt.executeQuery(sqlStatement);
784     while(rs.next())
785     {  result.addElement(rs.getString(1));
786     }
787   }
788   catch(SQLException e)
789   { //e.printStackTrace();
790     while((e = e.getNextException()) != null)
791     { //e.printStackTrace();
792     }
793   }
794 
795   sqlStatement = "SELECT height FROM " + db_name + " WHERE pict_url = " + "\"" 
796     + theURL + "\"";
797   try
798   { stmt = con.createStatement();
799     rs = stmt.executeQuery(sqlStatement);
800     while(rs.next())
801     {  result.addElement(rs.getString(1));
802     }
803   }
804   catch(SQLException e)
805   { //e.printStackTrace();
806     while((e = e.getNextException()) != null)
807     { //e.printStackTrace();
808     }
809   }
810 
811   sqlStatement = "SELECT iso_speed FROM " + db_name + " WHERE pict_url = " + "\"" 
812     + theURL + "\"";
813   try
814   { stmt = con.createStatement();
815     rs = stmt.executeQuery(sqlStatement);
816     while(rs.next())
817     {  result.addElement(rs.getString(1));
818     }
819   }
820   catch(SQLException e)
821   { //e.printStackTrace();
822     while((e = e.getNextException()) != null)
823     { //e.printStackTrace();
824     }
825   }
826 
827   sqlStatement = "SELECT exposure_mm FROM " + db_name + " WHERE pict_url = " + "\"" 
828     + theURL + "\"";
829   try
830   { stmt = con.createStatement();
831     rs = stmt.executeQuery(sqlStatement);
832     while(rs.next())
833     {  result.addElement(rs.getString(1));
834     }
835   }
836   catch(SQLException e)
837   { //e.printStackTrace();
838     while((e = e.getNextException()) != null)
839     { //e.printStackTrace();
840     }
841   }
842 
843   sqlStatement = "SELECT light_source FROM " + db_name + " WHERE pict_url = " + "\"" 
844     + theURL + "\"";
845   try
846   { stmt = con.createStatement();
847     rs = stmt.executeQuery(sqlStatement);
848     while(rs.next())
849     {  result.addElement(rs.getString(1));
850     }
851   }
852   catch(SQLException e)
853   { //e.printStackTrace();
854     while((e = e.getNextException()) != null)
855     { //e.printStackTrace();
856     }
857   }
858 
859   sqlStatement = "SELECT flash FROM " + db_name + " WHERE pict_url = " + "\"" 
860     + theURL + "\"";
861   try
862   { stmt = con.createStatement();
863     rs = stmt.executeQuery(sqlStatement);
864     while(rs.next())
865     {  result.addElement(rs.getString(1));
866     }
867   }
868   catch(SQLException e)
869   { //e.printStackTrace();
870     while((e = e.getNextException()) != null)
871     { //e.printStackTrace();
872     }
873   }
874 
875   sqlStatement = "SELECT color_space FROM " + db_name + " WHERE pict_url = " + "\"" 
876     + theURL + "\"";
877   try
878   { stmt = con.createStatement();
879     rs = stmt.executeQuery(sqlStatement);
880     while(rs.next())
881     {  result.addElement(rs.getString(1));
882     }
883   }
884   catch(SQLException e)
885   { //e.printStackTrace();
886     while((e = e.getNextException()) != null)
887     { //e.printStackTrace();
888     }
889   }
890 
891   sqlStatement = "SELECT exposure_program FROM " + db_name + " WHERE pict_url = " + "\"" 
892     + theURL + "\"";
893   try
894   { stmt = con.createStatement();
895     rs = stmt.executeQuery(sqlStatement);
896     while(rs.next())
897     {  result.addElement(rs.getString(1));
898     }
899   }
900   catch(SQLException e)
901   { //e.printStackTrace();
902     while((e = e.getNextException()) != null)
903     { //e.printStackTrace();
904     }
905   }
906 
907   //For debugging purposes only
908   int i;
909   int x = result.size();
910   for (i = 0; i < x; i++)
911     System.out.println(result.elementAt(i));
912 
913   return result;
914 }  
915 
916 /**
917  * Closes the connection with the database.
918  */
919 
920 public static void close()
921 {
922   try
923   { if(stmt != null)
924   stmt.close(); // flushes SQL statement
925     //System.out.println("statement buffer flushed");
926     if(con != null)
927   con.close(); // closes control connection
928     //System.out.println("control connection to database closed");
929   }
930   catch (SQLException e)
931   {  System.out.println("Error: " + e);
932   }
933 }
934     
935 /**
936  * Main method used only for internal test purposes
937  */
938  
939 public static void main(String[] args)
940 {
941   Database db = new Database("ydp");
942   db.create();
943   db.close();
944 }
945 }