KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > relique > jdbc > csv > CsvPreparedStatement


1 /**
2     Copyright (C) 2002-2003 Together
3
4     This library is free software; you can redistribute it and/or
5     modify it under the terms of the GNU Lesser General Public
6     License as published by the Free Software Foundation; either
7     version 2.1 of the License, or (at your option) any later version.
8
9     This library is distributed in the hope that it will be useful,
10     but WITHOUT ANY WARRANTY; without even the implied warranty of
11     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12     Lesser General Public License for more details.
13
14     You should have received a copy of the GNU Lesser General Public
15     License along with this library; if not, write to the Free Software
16     Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17
18 */

19
20
21 package org.relique.jdbc.csv;
22
23 import java.io.File JavaDoc;
24 import java.io.InputStream JavaDoc;
25 import java.io.Reader JavaDoc;
26 import java.math.BigDecimal JavaDoc;
27 import java.net.URL JavaDoc;
28 import java.sql.Array JavaDoc;
29 import java.sql.Blob JavaDoc;
30 import java.sql.Clob JavaDoc;
31 import java.sql.Connection JavaDoc;
32 import java.sql.Date JavaDoc;
33 import java.sql.DriverManager JavaDoc;
34 import java.sql.ParameterMetaData JavaDoc;
35 import java.sql.PreparedStatement JavaDoc;
36 import java.sql.Ref JavaDoc;
37 import java.sql.ResultSet JavaDoc;
38 import java.sql.ResultSetMetaData JavaDoc;
39 import java.sql.SQLException JavaDoc;
40 import java.sql.SQLWarning JavaDoc;
41 import java.sql.Time JavaDoc;
42 import java.sql.Timestamp JavaDoc;
43 import java.util.ArrayList JavaDoc;
44 import java.util.Calendar JavaDoc;
45 import java.util.Enumeration JavaDoc;
46 import java.util.Vector JavaDoc;
47
48 /**
49  * This class implements the PreparedStatement interface for the CsvJdbc driver.
50  *
51  * @author Zoran Milakovic
52  */

53 public class CsvPreparedStatement implements PreparedStatement JavaDoc {
54
55   private CsvConnection connection;
56   private Vector JavaDoc resultSets = new Vector JavaDoc();
57   private String JavaDoc sqlForPrepare = "";
58   private String JavaDoc sqlPrepared = "";
59   private int paramCount = 0;
60   private ArrayList JavaDoc parameters = new ArrayList JavaDoc();
61   private ArrayList JavaDoc binaryStreamParameters = new ArrayList JavaDoc();
62   private CsvWriter writeCsv;
63 /** Name used for prepared statement parameters */
64   public static String JavaDoc PREPARE_SEPARATOR = "~@#NEXTPARAMETER#@~";
65   private String JavaDoc sql;
66
67   public CsvPreparedStatement(CsvConnection connection, String JavaDoc preparedSql) {
68     DriverManager.println("CsvJdbc - CsvStatement() - connection=" + connection);
69     this.sqlForPrepare = preparedSql;
70     this.sqlPrepared = preparedSql;
71     this.paramCount = countParameters(preparedSql);
72     for ( int i = 0; i < paramCount; i++ )
73       parameters.add(null);
74     this.connection = connection;
75     try {
76       if(!connection.getAutoCommit())
77         writeCsv=new CsvWriter(
78               null,
79               connection.getSeperator(),
80               connection.getExtension(),
81               connection.getMaxFileSize(),
82               connection.getCharset(),
83               connection.getUseQuotes(),
84               connection.getUseQuotesEscape()
85               );
86     }
87     catch (Exception JavaDoc ex) {
88     ex.printStackTrace();
89     }
90   }
91
92   private int countParameters(String JavaDoc sql) {
93     int count = 0;
94     int index = sql.indexOf(PREPARE_SEPARATOR);
95     while( index != -1 ) {
96       count++;
97       sql = sql.substring(index+1);
98       index = sql.indexOf(PREPARE_SEPARATOR);
99     }
100     return count;
101   }
102
103   private boolean prepareSql() throws SQLException JavaDoc {
104     boolean retVal = true;
105     for (int i = 0; i < parameters.size(); i++) {
106       int index = sqlPrepared.indexOf(PREPARE_SEPARATOR);
107       String JavaDoc val;
108       if (index != -1) {
109         if( parameters.get(i) == null )
110           val = "null";
111         else
112           val = parameters.get(i).toString();
113         sqlPrepared = sqlPrepared.substring(0, index) +
114             val +
115             sqlPrepared.substring(index + PREPARE_SEPARATOR.length());
116       }
117     }
118     if (sqlPrepared.indexOf(PREPARE_SEPARATOR) != -1)
119       throw new SQLException JavaDoc(
120           "All ? in prepared query has to be replaced with values.");
121     else if (parameters.size() < this.paramCount)
122       throw new SQLException JavaDoc(
123           "Number of setted parameters is less than number of parameters in statement.");
124     else if (parameters.size() > this.paramCount)
125       throw new SQLException JavaDoc(
126           "Number of setted parameters is greater than number of parameters in statement.");
127
128     return retVal;
129   }
130
131   /**
132      *Sets the maxFieldSize attribute of the CsvStatement object
133      *
134      * @param p0 The new maxFieldSize value
135      * @exception SQLException Description of Exception
136      * @since
137      */

138     public void setMaxFieldSize(int p0) throws SQLException JavaDoc
139     {
140         throw new SQLException JavaDoc("Not Supported !");
141     }
142
143
144     /**
145      *Sets the maxRows attribute of the CsvStatement object
146      *
147      * @param p0 The new maxRows value
148      * @exception SQLException Description of Exception
149      * @since
150      */

151     public void setMaxRows(int p0) throws SQLException JavaDoc
152     {
153         throw new SQLException JavaDoc("Not Supported !");
154     }
155
156
157     /**
158      *Sets the escapeProcessing attribute of the CsvStatement object
159      *
160      * @param p0 The new escapeProcessing value
161      * @exception SQLException Description of Exception
162      * @since
163      */

164     public void setEscapeProcessing(boolean p0) throws SQLException JavaDoc
165     {
166         throw new SQLException JavaDoc("Not Supported !");
167     }
168
169
170     /**
171      *Sets the queryTimeout attribute of the CsvStatement object
172      *
173      * @param p0 The new queryTimeout value
174      * @exception SQLException Description of Exception
175      * @since
176      */

177     public void setQueryTimeout(int p0) throws SQLException JavaDoc
178     {
179         throw new SQLException JavaDoc("Not Supported !");
180     }
181
182
183     /**
184      *Sets the cursorName attribute of the CsvStatement object
185      *
186      * @param p0 The new cursorName value
187      * @exception SQLException Description of Exception
188      * @since
189      */

190     public void setCursorName(String JavaDoc p0) throws SQLException JavaDoc
191     {
192         throw new SQLException JavaDoc("Not Supported !");
193     }
194
195
196     /**
197      *Sets the fetchDirection attribute of the CsvStatement object
198      *
199      * @param p0 The new fetchDirection value
200      * @exception SQLException Description of Exception
201      * @since
202      */

203     public void setFetchDirection(int p0) throws SQLException JavaDoc
204     {
205         throw new SQLException JavaDoc("Not Supported !");
206     }
207
208
209     /**
210      *Sets the fetchSize attribute of the CsvStatement object
211      *
212      * @param p0 The new fetchSize value
213      * @exception SQLException Description of Exception
214      * @since
215      */

216     public void setFetchSize(int p0) throws SQLException JavaDoc
217     {
218         throw new SQLException JavaDoc("Not Supported !");
219     }
220
221
222     /**
223      *Gets the maxFieldSize attribute of the CsvStatement object
224      *
225      * @return The maxFieldSize value
226      * @exception SQLException Description of Exception
227      * @since
228      */

229     public int getMaxFieldSize() throws SQLException JavaDoc
230     {
231         throw new SQLException JavaDoc("Not Supported !");
232     }
233
234
235     /**
236      *Gets the maxRows attribute of the CsvStatement object
237      *
238      * @return The maxRows value
239      * @exception SQLException Description of Exception
240      * @since
241      */

242     public int getMaxRows() throws SQLException JavaDoc
243     {
244         throw new SQLException JavaDoc("Not Supported !");
245     }
246
247
248     /**
249      *Gets the queryTimeout attribute of the CsvStatement object
250      *
251      * @return The queryTimeout value
252      * @exception SQLException Description of Exception
253      * @since
254      */

255     public int getQueryTimeout() throws SQLException JavaDoc
256     {
257         throw new SQLException JavaDoc("Not Supported !");
258     }
259
260
261     /**
262      *Gets the warnings attribute of the CsvStatement object
263      *
264      * @return The warnings value
265      * @exception SQLException Description of Exception
266      * @since
267      */

268     public SQLWarning JavaDoc getWarnings() throws SQLException JavaDoc
269     {
270         throw new SQLException JavaDoc("Not Supported !");
271     }
272
273
274     /**
275      *Gets the resultSet attribute of the CsvStatement object
276      *
277      * @return The resultSet value
278      * @exception SQLException Description of Exception
279      * @since
280      */

281     public ResultSet JavaDoc getResultSet() throws SQLException JavaDoc
282     {
283         throw new SQLException JavaDoc("Not Supported !");
284     }
285
286
287     /**
288      *Gets the updateCount attribute of the CsvStatement object
289      *
290      * @return The updateCount value
291      * @exception SQLException Description of Exception
292      * @since
293      */

294     public int getUpdateCount() throws SQLException JavaDoc
295     {
296         throw new SQLException JavaDoc("Not Supported !");
297     }
298
299
300     /**
301      *Gets the moreResults attribute of the CsvStatement object
302      *
303      * @return The moreResults value
304      * @exception SQLException Description of Exception
305      * @since
306      */

307     public boolean getMoreResults() throws SQLException JavaDoc
308     {
309         throw new SQLException JavaDoc("Not Supported !");
310     }
311
312
313     /**
314      *Gets the fetchDirection attribute of the CsvStatement object
315      *
316      * @return The fetchDirection value
317      * @exception SQLException Description of Exception
318      * @since
319      */

320     public int getFetchDirection() throws SQLException JavaDoc
321     {
322         throw new SQLException JavaDoc("Not Supported !");
323     }
324
325
326     /**
327      *Gets the fetchSize attribute of the CsvStatement object
328      *
329      * @return The fetchSize value
330      * @exception SQLException Description of Exception
331      * @since
332      */

333     public int getFetchSize() throws SQLException JavaDoc
334     {
335         throw new SQLException JavaDoc("Not Supported !");
336     }
337
338
339     /**
340      *Gets the resultSetConcurrency attribute of the CsvStatement object
341      *
342      * @return The resultSetConcurrency value
343      * @exception SQLException Description of Exception
344      * @since
345      */

346     public int getResultSetConcurrency() throws SQLException JavaDoc
347     {
348         throw new SQLException JavaDoc("Not Supported !");
349     }
350
351
352     /**
353      *Gets the resultSetType attribute of the CsvStatement object
354      *
355      * @return The resultSetType value
356      * @exception SQLException Description of Exception
357      * @since
358      */

359     public int getResultSetType() throws SQLException JavaDoc
360     {
361         throw new SQLException JavaDoc("Not Supported !");
362     }
363
364
365     /**
366      *Gets the connection attribute of the CsvStatement object
367      *
368      * @return The connection value
369      * @exception SQLException Description of Exception
370      * @since
371      */

372     public Connection JavaDoc getConnection() throws SQLException JavaDoc
373     {
374         return connection;
375     }
376
377
378     /**
379      *Description of the Method
380      *
381      * @param sql Description of Parameter
382      * @return Description of the Returned Value
383      * @exception SQLException Description of Exception
384      * @since
385      */

386     public ResultSet JavaDoc executeQuery(String JavaDoc sql) throws SQLException JavaDoc
387     {
388         DriverManager.println("CsvJdbc - CsvStatement:executeQuery() - sql= " + sql);
389         CsvSqlParser parser = new CsvSqlParser();
390         if( binaryStreamParameters.size() != 0 )
391           parser.setBinaryStreamList( binaryStreamParameters );
392
393         this.sql = sql;
394         try
395             {
396                 parser.parse(this);
397             }
398         catch (Exception JavaDoc e)
399             {
400                 throw new SQLException JavaDoc("Syntax Error. " + e.getMessage());
401             }
402
403     String JavaDoc fileName = connection.getPath() + parser.getTableName() + connection.getExtension();
404     File JavaDoc checkFile = new File JavaDoc(fileName);
405     if (!checkFile.exists())
406     {
407       throw new SQLException JavaDoc("Cannot open data file '" + fileName + "' !");
408     }
409
410     if (!checkFile.canRead())
411     {
412       throw new SQLException JavaDoc("Data file '" + fileName + "' not readable !");
413     }
414     CsvReader reader;
415     try
416     {
417       reader = new CsvReader(fileName,
418                              connection.getSeperator(),
419                              connection.isSuppressHeaders(),
420                              connection.getCharset(),
421                              connection.getExtension(),
422                              connection.getLineBreakEscape(),
423 // connection.getDoubleQuotesEscape(),
424
connection.getCarriageReturnEscape()
425                              );
426       String JavaDoc[] xxx = parser.getColumnNames();
427       String JavaDoc[] yyy = reader.getColumnNames();
428       boolean isOK = true;
429       for(int i=0; i< xxx.length; i++) {
430       if(!xxx[i].endsWith("*")) {
431        out:
432       for(int j=0; j< yyy.length; j++) {
433          if(xxx[i].equalsIgnoreCase( yyy[j] )) {
434             isOK=true;
435             break out;
436           }
437           else
438             isOK=false;
439         }
440        if(!isOK)
441         throw new SQLException JavaDoc("Column '" + xxx[i] + "' not found.");
442       }
443       }
444     }
445     catch (Exception JavaDoc e)
446     {
447       throw new SQLException JavaDoc("Error reading data file. Message was: " + e);
448     }
449     CsvResultSet resultSet = new CsvResultSet(this, reader,
450             parser.getTableName(), parser.getColumnNames(), parser.getWhereColumnNames(),
451             parser.getWhereColumnValues(), reader.getColumnTypes());
452     resultSets.add(resultSet);
453     return resultSet;
454   }
455
456
457
458     /**
459      *Description of the Method
460      *
461      * @param sql Description of Parameter
462      * @return Description of the Returned Value
463      * @exception SQLException Description of Exception
464      * @since
465      */

466     public int executeUpdate(String JavaDoc sql) throws SQLException JavaDoc
467     {
468     int updated=0;
469     DriverManager.println("CsvJdbc - CsvStatement:executeUpdate() - sql= " + sql);
470     CsvSqlParser parser = new CsvSqlParser();
471     if( binaryStreamParameters.size() != 0 )
472           parser.setBinaryStreamList( binaryStreamParameters );
473     this.sql = sql;
474     try
475     {
476       parser.parse(this);
477     }
478     catch (Exception JavaDoc e)
479     {
480       throw new SQLException JavaDoc("Syntax Error. " + e.getMessage());
481     }
482       if(parser.sqlType.equals(parser.SELECT))
483               throw new SQLException JavaDoc("Not supported SELECT statement - use executeQuery method");
484       else if (parser.sqlType.equals(parser.CREATE_TABLE)) {
485                   throw new SQLException JavaDoc("Not supported CREATE TABLE statement - use execute method");
486       }
487       else if (parser.sqlType.equals(parser.INSERT)) {
488             String JavaDoc fileName = connection.getPath() + parser.getTableName() + connection.getExtension();
489             File JavaDoc checkFile = new File JavaDoc(fileName);
490
491             if (!checkFile.exists())
492             {
493               throw new SQLException JavaDoc("Cannot open data file '" + fileName + "' !");
494             }
495
496             if (!checkFile.canWrite())
497             {
498               throw new SQLException JavaDoc("Data file '" + fileName + "' is read only !");
499             }
500 // CsvWriter writeCsv;
501
try
502             {
503               if(connection.getAutoCommit())
504                 writeCsv = new CsvWriter(
505                   fileName,
506                   connection.getSeperator(),
507                   connection.getExtension(),
508                   connection.getMaxFileSize(),
509                   connection.getCharset(),
510                   connection.getUseQuotes(),
511                   connection.getUseQuotesEscape()
512                   );
513               else {
514                 writeCsv.setFileName(fileName);
515                 writeCsv.fillTableColumnNames();
516               }
517
518                 String JavaDoc[] xxx = parser.getColumnNames();
519                 String JavaDoc[] yyy = writeCsv.getColumnNames();
520                 boolean isOK = true;
521                 for(int i=0; i< xxx.length; i++) {
522                   if(!xxx[i].endsWith("*")) {
523                   out:
524                   for(int j=0; j< yyy.length; j++) {
525                     if(xxx[i].equalsIgnoreCase( yyy[j] )) {
526                       isOK=true;
527                       break out;
528                     }
529                   else
530                     isOK=false;
531                   }
532                 if(!isOK)
533                   throw new SQLException JavaDoc("Column '" + xxx[i] + "' not found.");
534                 }
535               }
536               writeCsv.newLine(parser.columnNames, parser.columnValues);
537
538             }
539             catch (Exception JavaDoc e)
540             {
541               e.printStackTrace();
542               throw new SQLException JavaDoc("Error reading data file. Message was: " + e);
543             }
544
545       }
546       else if (parser.sqlType.equals(parser.UPDATE)) {
547
548             String JavaDoc fileName = connection.getPath() + parser.getTableName() + connection.getExtension();
549             File JavaDoc checkFile = new File JavaDoc(fileName);
550
551             if (!checkFile.exists())
552             {
553               throw new SQLException JavaDoc("Cannot open data file '" + fileName + "' !");
554             }
555
556             if (!checkFile.canWrite())
557             {
558               throw new SQLException JavaDoc("Data file '" + fileName + "' is read only !");
559             }
560 // CsvWriter writeCsv;
561
try
562             {
563               if(connection.getAutoCommit())
564                 writeCsv = new CsvWriter(
565               fileName,
566               connection.getSeperator(),
567               connection.getExtension(),
568               connection.getMaxFileSize(),
569               connection.getCharset(),
570               connection.getUseQuotes(),
571               connection.getUseQuotesEscape()
572               );
573               else{
574                writeCsv.setFileName(fileName);
575                writeCsv.fillTableColumnNames();
576               }
577
578                 String JavaDoc[] xxx = parser.getColumnNames();
579                 String JavaDoc[] yyy = writeCsv.getColumnNames();
580                 boolean isOK = true;
581                 for(int i=0; i< xxx.length; i++) {
582                   if(!xxx[i].endsWith("*")) {
583                     out:
584                   for(int j=0; j< yyy.length; j++) {
585                     if(xxx[i].equalsIgnoreCase( yyy[j] )) {
586                       isOK=true;
587                       break out;
588                     }
589                   else
590                     isOK=false;
591                 }
592                 if(!isOK)
593                   throw new SQLException JavaDoc("Column '" + xxx[i] + "' not found.");
594                   }
595                 }
596                 if(!writeCsv.updateFields(parser.columnNames, parser.columnValues, parser.columnWhereNames, parser.columnWhereValues))
597                   updated = -1;
598             }
599             catch (Exception JavaDoc e)
600             {
601               throw new SQLException JavaDoc("Error reading data file. Message was: " + e);
602             }
603
604         }
605       return updated;
606
607   }
608
609
610     /**
611      * Releases this <code>Statement</code> object's database
612      * and JDBC resources immediately instead of waiting for
613      * this to happen when it is automatically closed.
614      * It is generally good practice to release resources as soon as
615      * you are finished with them to avoid tying up database
616      * resources.
617      * <P>
618      * Calling the method <code>close</code> on a <code>Statement</code>
619      * object that is already closed has no effect.
620      * <P>
621      * <B>Note:</B> A <code>Statement</code> object is automatically closed
622      * when it is garbage collected. When a <code>Statement</code> object is
623      * closed, its current <code>ResultSet</code> object, if one exists, is
624      * also closed.
625      *
626      * @exception SQLException if a database access error occurs
627      */

628     public void close() throws SQLException JavaDoc {
629       // close all result sets
630
for(Enumeration JavaDoc i = resultSets.elements(); i.hasMoreElements(); ) {
631         CsvResultSet resultSet = (CsvResultSet) i.nextElement();
632         resultSet.close();
633       }
634       try {
635             if(this.writeCsv != null)
636             this.writeCsv.close();
637       }
638       catch(Exception JavaDoc e) {
639         e.printStackTrace();
640         throw new SQLException JavaDoc(e.getMessage());
641       }
642     }
643
644     /**
645      *Description of the Method
646      *
647      * @exception SQLException Description of Exception
648      * @since
649      */

650     public void cancel() throws SQLException JavaDoc
651     {
652         throw new SQLException JavaDoc("Not Supported !");
653     }
654
655
656     /**
657      *Description of the Method
658      *
659      * @exception SQLException Description of Exception
660      * @since
661      */

662     public void clearWarnings() throws SQLException JavaDoc
663     {
664         throw new SQLException JavaDoc("Not Supported !");
665     }
666
667
668     /**
669      *Description of the Method
670      *
671      * @param sql Description of Parameter
672      * @return Description of the Returned Value
673      * @exception SQLException Description of Exception
674      * @since
675      */

676     public boolean execute(String JavaDoc sql) throws SQLException JavaDoc
677   {
678     CsvSqlParser parser = new CsvSqlParser();
679     if( binaryStreamParameters.size() != 0 )
680           parser.setBinaryStreamList( binaryStreamParameters );
681     this.sql = sql;
682     try
683     {
684       parser.parse(this);
685     }
686     catch (Exception JavaDoc e)
687     {
688       throw new SQLException JavaDoc("Syntax Error. " + e.getMessage());
689     }
690       if(parser.sqlType.equals(parser.SELECT))
691               throw new SQLException JavaDoc("Not supported SELECT statement - use executeQuery method");
692       else if (parser.sqlType.equals(parser.INSERT))
693               executeUpdate(sql);
694        else if (parser.sqlType.equals(parser.CREATE_TABLE)) {
695              String JavaDoc fileName = connection.getPath() + parser.getTableName() + connection.getExtension();
696             File JavaDoc checkFile = new File JavaDoc(fileName);
697
698             if (checkFile.exists())
699             {
700               throw new SQLException JavaDoc("Data file '" + fileName + "'already exists !");
701             }
702
703 // CsvWriter writeCsv;
704
try
705             {
706               if(connection.getAutoCommit())
707                 writeCsv = new CsvWriter(
708               fileName,
709               connection.getSeperator(),
710               connection.getExtension(),
711               connection.getMaxFileSize(),
712               connection.getCharset(),
713               connection.getUseQuotes(),
714               connection.getUseQuotesEscape()
715               );
716               else{
717                 writeCsv.setFileName(fileName);
718                 writeCsv.fillTableColumnNames();
719               }
720
721               writeCsv.createTable(parser.columnNames, fileName);
722             }
723             catch (Exception JavaDoc e)
724             {
725               throw new SQLException JavaDoc("Error reading data file. Message was: " + e);
726             }
727         }
728         return true;
729
730   }
731
732   /**
733    * Set String as parameter in sql statement.
734    * @param parameterIndex
735    * @param value
736    * @throws SQLException
737    */

738   public void setString(int parameterIndex, String JavaDoc value) throws SQLException JavaDoc {
739     if( value == null ) {
740       CsvDriver.log("value = null object");
741       parameters.set(parameterIndex - 1, value);
742     } else {
743       value = Utils.replaceAll(value, "'", CsvSqlParser.QUOTE_ESCAPE);
744       CsvDriver.log("value = " + value);
745       parameters.set(parameterIndex - 1, "'" + value + "'");
746     }
747   }
748
749
750   /**
751    *
752    * @param parameterIndex
753    * @param value
754    * @throws SQLException
755    */

756   public void setBytes(int parameterIndex, byte[] value) throws SQLException JavaDoc {
757     binaryStreamParameters.add(Utils.bytesToHexString(value));
758     String JavaDoc paramName = CsvSqlParser.BINARY_STREAM_OBJECT+""+binaryStreamParameters.size();
759     parameters.set(parameterIndex-1, paramName);
760   }
761
762     /**
763      *Adds a feature to the Batch attribute of the CsvStatement object
764      *
765      * @param p0 The feature to be added to the Batch attribute
766      * @exception SQLException Description of Exception
767      * @since
768      */

769     public void addBatch(String JavaDoc p0) throws SQLException JavaDoc
770     {
771         throw new SQLException JavaDoc("Not Supported !");
772     }
773
774
775     /**
776      *Description of the Method
777      *
778      * @exception SQLException Description of Exception
779      * @since
780      */

781     public void clearBatch() throws SQLException JavaDoc
782     {
783         throw new SQLException JavaDoc("Not Supported !");
784     }
785
786
787     /**
788      *Description of the Method
789      *
790      * @return Description of the Returned Value
791      * @exception SQLException Description of Exception
792      * @since
793      */

794     public int[] executeBatch() throws SQLException JavaDoc
795     {
796         throw new SQLException JavaDoc("Not Supported !");
797     }
798
799     //---------------------------------------------------------------------
800
// JDBC 3.0
801
//---------------------------------------------------------------------
802

803     public boolean getMoreResults(int current) throws SQLException JavaDoc {
804         throw new UnsupportedOperationException JavaDoc("Statement.getMoreResults(int) unsupported");
805     }
806
807     public ResultSet JavaDoc getGeneratedKeys() throws SQLException JavaDoc {
808         throw new UnsupportedOperationException JavaDoc("Statement.getGeneratedKeys() unsupported");
809     }
810
811     public int executeUpdate(String JavaDoc sql, int autoGeneratedKeys) throws SQLException JavaDoc {
812         throw new UnsupportedOperationException JavaDoc("Statement.executeUpdate(String,int) unsupported");
813     }
814
815     public int executeUpdate(String JavaDoc sql, int[] columnIndexes) throws SQLException JavaDoc {
816         throw new UnsupportedOperationException JavaDoc("Statement.executeUpdate(String,int[]) unsupported");
817     }
818
819     public int executeUpdate(String JavaDoc sql, String JavaDoc[] columnNames) throws SQLException JavaDoc {
820         throw new UnsupportedOperationException JavaDoc("Statement.executeUpdate(String,String[]) unsupported");
821     }
822
823     public boolean execute(String JavaDoc sql, int autoGeneratedKeys) throws SQLException JavaDoc {
824         throw new UnsupportedOperationException JavaDoc("Statement.execute(String,int) unsupported");
825     }
826
827     public boolean execute(String JavaDoc sql, int[] columnIndexes) throws SQLException JavaDoc {
828         throw new UnsupportedOperationException JavaDoc("Statement.execute(String,int[]) unsupported");
829     }
830
831     public boolean execute(String JavaDoc sql, String JavaDoc[] columnNames) throws SQLException JavaDoc {
832         throw new UnsupportedOperationException JavaDoc("Statement.execute(String,String[]) unsupported");
833     }
834
835     public int getResultSetHoldability() throws SQLException JavaDoc {
836         throw new UnsupportedOperationException JavaDoc("Statement.getResultSetHoldability() unsupported");
837     }
838
839
840
841   public ResultSet JavaDoc executeQuery() throws SQLException JavaDoc {
842     if( !prepareSql())
843         throw new SQLException JavaDoc("Error with prepared statement !");
844     return executeQuery(this.sqlPrepared);
845
846   }
847   public int executeUpdate() throws SQLException JavaDoc {
848     if( !prepareSql())
849         throw new SQLException JavaDoc("Error with prepared statement !");
850     executeUpdate(this.sqlPrepared);
851     return 0;
852   }
853
854
855
856
857
858   public void setNull(int parameterIndex, int sqlType) throws SQLException JavaDoc {
859     this.setString(parameterIndex, null );
860   }
861
862   public void setBoolean(int parameterIndex, boolean value) throws SQLException JavaDoc {
863     this.setString(parameterIndex, String.valueOf(value) );
864   }
865
866   public void setByte(int parameterIndex, byte value) throws SQLException JavaDoc {
867     this.setString(parameterIndex, String.valueOf(value) );
868   }
869
870   public void setShort(int parameterIndex, short value) throws SQLException JavaDoc {
871     this.setString(parameterIndex, String.valueOf(value) );
872   }
873
874   public void setInt(int parameterIndex, int value) throws SQLException JavaDoc {
875     this.setString(parameterIndex, String.valueOf(value) );
876   }
877
878   public void setLong(int parameterIndex, long value) throws SQLException JavaDoc {
879     this.setString(parameterIndex, String.valueOf(value) );
880   }
881
882   public void setFloat(int parameterIndex, float value) throws SQLException JavaDoc {
883     this.setString(parameterIndex, String.valueOf(value) );
884   }
885
886   public void setDouble(int parameterIndex, double value) throws SQLException JavaDoc {
887     this.setString(parameterIndex, String.valueOf(value) );
888   }
889
890   public void setBigDecimal(int parameterIndex, BigDecimal JavaDoc value) throws SQLException JavaDoc {
891       if(value == null) {
892           this.setString( parameterIndex, value.toString() );
893       } else {
894           this.setString( parameterIndex, "" );
895       }
896   }
897   
898   public void setDate(int parameterIndex, Date JavaDoc value) throws SQLException JavaDoc {
899       if(value == null) {
900           this.setString( parameterIndex, value.toString() );
901       } else {
902           this.setString( parameterIndex, "" );
903       }
904   }
905   
906   public void setTime(int parameterIndex, Time JavaDoc value) throws SQLException JavaDoc {
907       if(value == null) {
908           this.setString( parameterIndex, value.toString() );
909       } else {
910           this.setString( parameterIndex, "" );
911       }
912   }
913   
914   public void setTimestamp(int parameterIndex, Timestamp JavaDoc value) throws SQLException JavaDoc {
915       if(value == null) {
916           this.setString( parameterIndex, value.toString() );
917       } else {
918           this.setString( parameterIndex, "" );
919       }
920   }
921   
922   public void setAsciiStream(int parameterIndex, InputStream JavaDoc x, int length) throws SQLException JavaDoc {
923     /**@todo Implement this java.sql.PreparedStatement method*/
924     throw new java.lang.UnsupportedOperationException JavaDoc("Method setAsciiStream() not yet implemented.");
925   }
926   public void setUnicodeStream(int parameterIndex, InputStream JavaDoc x, int length) throws SQLException JavaDoc {
927     /**@todo Implement this java.sql.PreparedStatement method*/
928     throw new java.lang.UnsupportedOperationException JavaDoc("Method setUnicodeStream() not yet implemented.");
929   }
930
931   public void clearParameters() throws SQLException JavaDoc {
932     this.sqlPrepared = this.sqlForPrepare;
933     for(int i = 0; i < parameters.size(); i++)
934       parameters.set(i, null);
935   }
936   public void setObject(int parameterIndex, Object JavaDoc x, int targetSqlType, int scale) throws SQLException JavaDoc {
937     /**@todo Implement this java.sql.PreparedStatement method*/
938     throw new java.lang.UnsupportedOperationException JavaDoc("Method setObject() not yet implemented.");
939   }
940   public void setObject(int parameterIndex, Object JavaDoc x, int targetSqlType) throws SQLException JavaDoc {
941     /**@todo Implement this java.sql.PreparedStatement method*/
942     throw new java.lang.UnsupportedOperationException JavaDoc("Method setObject() not yet implemented.");
943   }
944   public void setObject(int parameterIndex, Object JavaDoc x) throws SQLException JavaDoc {
945     if( x == null )
946        setString(parameterIndex, null);
947     else
948        setString( parameterIndex, x.toString() );
949   }
950   public boolean execute() throws SQLException JavaDoc {
951     /**@todo Implement this java.sql.PreparedStatement method*/
952     throw new java.lang.UnsupportedOperationException JavaDoc("Method execute() not yet implemented.");
953   }
954   public void addBatch() throws SQLException JavaDoc {
955     /**@todo Implement this java.sql.PreparedStatement method*/
956     throw new java.lang.UnsupportedOperationException JavaDoc("Method addBatch() not yet implemented.");
957   }
958   public void setCharacterStream(int parameterIndex, Reader JavaDoc reader, int length) throws SQLException JavaDoc {
959     /**@todo Implement this java.sql.PreparedStatement method*/
960     throw new java.lang.UnsupportedOperationException JavaDoc("Method setCharacterStream() not yet implemented.");
961   }
962   public void setRef(int i, Ref JavaDoc x) throws SQLException JavaDoc {
963     /**@todo Implement this java.sql.PreparedStatement method*/
964     throw new java.lang.UnsupportedOperationException JavaDoc("Method setRef() not yet implemented.");
965   }
966
967   public void setClob(int i, Clob JavaDoc x) throws SQLException JavaDoc {
968     /**@todo Implement this java.sql.PreparedStatement method*/
969     throw new java.lang.UnsupportedOperationException JavaDoc("Method setClob() not yet implemented.");
970   }
971   public void setArray(int i, Array JavaDoc x) throws SQLException JavaDoc {
972     /**@todo Implement this java.sql.PreparedStatement method*/
973     throw new java.lang.UnsupportedOperationException JavaDoc("Method setArray() not yet implemented.");
974   }
975   public ResultSetMetaData JavaDoc getMetaData() throws SQLException JavaDoc {
976     /**@todo Implement this java.sql.PreparedStatement method*/
977     throw new java.lang.UnsupportedOperationException JavaDoc("Method getMetaData() not yet implemented.");
978   }
979   public void setDate(int parameterIndex, Date JavaDoc x, Calendar JavaDoc cal) throws SQLException JavaDoc {
980     /**@todo Implement this java.sql.PreparedStatement method*/
981     throw new java.lang.UnsupportedOperationException JavaDoc("Method setDate() not yet implemented.");
982   }
983   public void setTime(int parameterIndex, Time JavaDoc x, Calendar JavaDoc cal) throws SQLException JavaDoc {
984     /**@todo Implement this java.sql.PreparedStatement method*/
985     throw new java.lang.UnsupportedOperationException JavaDoc("Method setTime() not yet implemented.");
986   }
987   public void setTimestamp(int parameterIndex, Timestamp JavaDoc x, Calendar JavaDoc cal) throws SQLException JavaDoc {
988     /**@todo Implement this java.sql.PreparedStatement method*/
989     throw new java.lang.UnsupportedOperationException JavaDoc("Method setTimestamp() not yet implemented.");
990   }
991   public void setNull(int paramIndex, int sqlType, String JavaDoc typeName) throws SQLException JavaDoc {
992     this.setString(paramIndex, null );
993   }
994
995   public void setURL(int parameterIndex, URL JavaDoc x) throws SQLException JavaDoc {
996     /**@todo Implement this java.sql.PreparedStatement method*/
997     throw new java.lang.UnsupportedOperationException JavaDoc(
998         "Method setURL() not yet implemented.");
999   }
1000
1001  public ParameterMetaData JavaDoc getParameterMetaData() throws SQLException JavaDoc {
1002    /**@todo Implement this java.sql.PreparedStatement method*/
1003    throw new java.lang.UnsupportedOperationException JavaDoc(
1004        "Method getParameterMetaData() not yet implemented.");
1005  }
1006
1007  public void setBinaryStream(int parameterIndex, InputStream JavaDoc value, int length) throws
1008      SQLException JavaDoc {
1009      try {
1010        String JavaDoc hex = Utils.streamToHexString(value);
1011        this.setBytes(parameterIndex,Utils.hexStringToBytes(hex));
1012      } catch (Exception JavaDoc e) {
1013         throw new SQLException JavaDoc("Error in setBinaryStream(): "+e.getMessage());
1014      }
1015  }
1016
1017  public void setBlob(int parameterIndex, Blob JavaDoc value) throws SQLException JavaDoc {
1018    /**@todo Implement this java.sql.PreparedStatement method*/
1019    throw new java.lang.UnsupportedOperationException JavaDoc(
1020        "Method setBlob() not yet implemented.");
1021  }
1022
1023  public String JavaDoc getSqlStatement() {
1024      return sql;
1025    }
1026
1027}
Popular Tags