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;
24 import java.io.InputStream;
25 import java.io.Reader;
26 import java.math.BigDecimal;
27 import java.net.URL;
28 import java.sql.Array;
29 import java.sql.Blob;
30 import java.sql.Clob;
31 import java.sql.Connection;
32 import java.sql.Date;
33 import java.sql.DriverManager;
34 import java.sql.ParameterMetaData;
35 import java.sql.PreparedStatement;
36 import java.sql.Ref;
37 import java.sql.ResultSet;
38 import java.sql.ResultSetMetaData;
39 import java.sql.SQLException;
40 import java.sql.SQLWarning;
41 import java.sql.Time;
42 import java.sql.Timestamp;
43 import java.util.ArrayList;
44 import java.util.Calendar;
45 import java.util.Enumeration;
46 import java.util.Vector;
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 {
54
55 private CsvConnection connection;
56 private Vector resultSets = new Vector();
57 private String sqlForPrepare = "";
58 private String sqlPrepared = "";
59 private int paramCount = 0;
60 private ArrayList parameters = new ArrayList();
61 private ArrayList binaryStreamParameters = new ArrayList();
62 private CsvWriter writeCsv;
63 /*** Name used for prepared statement parameters */
64 public static String PREPARE_SEPARATOR = "~@#NEXTPARAMETER#@~";
65 private String sql;
66
67 public CsvPreparedStatement(CsvConnection connection, String 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 ex) {
88 ex.printStackTrace();
89 }
90 }
91
92 private int countParameters(String 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 {
104 boolean retVal = true;
105 for (int i = 0; i < parameters.size(); i++) {
106 int index = sqlPrepared.indexOf(PREPARE_SEPARATOR);
107 String 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(
120 "All ? in prepared query has to be replaced with values.");
121 else if (parameters.size() < this.paramCount)
122 throw new SQLException(
123 "Number of setted parameters is less than number of parameters in statement.");
124 else if (parameters.size() > this.paramCount)
125 throw new SQLException(
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
139 {
140 throw new SQLException("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
152 {
153 throw new SQLException("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
165 {
166 throw new SQLException("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
178 {
179 throw new SQLException("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 p0) throws SQLException
191 {
192 throw new SQLException("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
204 {
205 throw new SQLException("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
217 {
218 throw new SQLException("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
230 {
231 throw new SQLException("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
243 {
244 throw new SQLException("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
256 {
257 throw new SQLException("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 getWarnings() throws SQLException
269 {
270 throw new SQLException("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 getResultSet() throws SQLException
282 {
283 throw new SQLException("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
295 {
296 throw new SQLException("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
308 {
309 throw new SQLException("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
321 {
322 throw new SQLException("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
334 {
335 throw new SQLException("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
347 {
348 throw new SQLException("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
360 {
361 throw new SQLException("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 getConnection() throws SQLException
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 executeQuery(String sql) throws SQLException
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 e)
399 {
400 throw new SQLException("Syntax Error. " + e.getMessage());
401 }
402
403 String fileName = connection.getPath() + parser.getTableName() + connection.getExtension();
404 File checkFile = new File(fileName);
405 if (!checkFile.exists())
406 {
407 throw new SQLException("Cannot open data file '" + fileName + "' !");
408 }
409
410 if (!checkFile.canRead())
411 {
412 throw new SQLException("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 connection.isTrimString()
426 );
427 String[] xxx = parser.getColumnNames();
428 String[] yyy = reader.getColumnNames();
429 boolean isOK = true;
430 for(int i=0; i< xxx.length; i++) {
431 if(!xxx[i].endsWith("*")) {
432 out:
433 for(int j=0; j< yyy.length; j++) {
434 if(xxx[i].equalsIgnoreCase( yyy[j] )) {
435 isOK=true;
436 break out;
437 }
438 else
439 isOK=false;
440 }
441 if(!isOK)
442 throw new SQLException("Column '" + xxx[i] + "' not found.");
443 }
444 }
445 }
446 catch (Exception e)
447 {
448 throw new SQLException("Error reading data file. Message was: " + e);
449 }
450 CsvResultSet resultSet = new CsvResultSet(this, reader,
451 parser.getTableName(), parser.getColumnNames(), parser.getWhereColumnNames(),
452 parser.getWhereColumnValues(), reader.getColumnTypes());
453 resultSets.add(resultSet);
454 return resultSet;
455 }
456
457
458
459 /***
460 *Description of the Method
461 *
462 * @param sql Description of Parameter
463 * @return Description of the Returned Value
464 * @exception SQLException Description of Exception
465 * @since
466 */
467 public int executeUpdate(String sql) throws SQLException
468 {
469 int updated=0;
470 DriverManager.println("CsvJdbc - CsvStatement:executeUpdate() - sql= " + sql);
471 CsvSqlParser parser = new CsvSqlParser();
472 if( binaryStreamParameters.size() != 0 )
473 parser.setBinaryStreamList( binaryStreamParameters );
474 this.sql = sql;
475 try
476 {
477 parser.parse(this);
478 }
479 catch (Exception e)
480 {
481 throw new SQLException("Syntax Error. " + e.getMessage());
482 }
483 if(parser.sqlType.equals(parser.SELECT))
484 throw new SQLException("Not supported SELECT statement - use executeQuery method");
485 else if (parser.sqlType.equals(parser.CREATE_TABLE)) {
486 throw new SQLException("Not supported CREATE TABLE statement - use execute method");
487 }
488 else if (parser.sqlType.equals(parser.INSERT)) {
489 String fileName = connection.getPath() + parser.getTableName() + connection.getExtension();
490 File checkFile = new File(fileName);
491
492 if (!checkFile.exists())
493 {
494 throw new SQLException("Cannot open data file '" + fileName + "' !");
495 }
496
497 if (!checkFile.canWrite())
498 {
499 throw new SQLException("Data file '" + fileName + "' is read only !");
500 }
501 // CsvWriter writeCsv;
502 try
503 {
504 if(connection.getAutoCommit())
505 writeCsv = new CsvWriter(
506 fileName,
507 connection.getSeperator(),
508 connection.getExtension(),
509 connection.getMaxFileSize(),
510 connection.getCharset(),
511 connection.getUseQuotes(),
512 connection.getUseQuotesEscape()
513 );
514 else {
515 writeCsv.setFileName(fileName);
516 writeCsv.fillTableColumnNames();
517 }
518
519 String[] xxx = parser.getColumnNames();
520 String[] yyy = writeCsv.getColumnNames();
521 boolean isOK = true;
522 for(int i=0; i< xxx.length; i++) {
523 if(!xxx[i].endsWith("*")) {
524 out:
525 for(int j=0; j< yyy.length; j++) {
526 if(xxx[i].equalsIgnoreCase( yyy[j] )) {
527 isOK=true;
528 break out;
529 }
530 else
531 isOK=false;
532 }
533 if(!isOK)
534 throw new SQLException("Column '" + xxx[i] + "' not found.");
535 }
536 }
537 writeCsv.newLine(parser.columnNames, parser.columnValues);
538
539 }
540 catch (Exception e)
541 {
542 e.printStackTrace();
543 throw new SQLException("Error reading data file. Message was: " + e);
544 }
545
546 }
547 else if (parser.sqlType.equals(parser.UPDATE)) {
548
549 String fileName = connection.getPath() + parser.getTableName() + connection.getExtension();
550 File checkFile = new File(fileName);
551
552 if (!checkFile.exists())
553 {
554 throw new SQLException("Cannot open data file '" + fileName + "' !");
555 }
556
557 if (!checkFile.canWrite())
558 {
559 throw new SQLException("Data file '" + fileName + "' is read only !");
560 }
561 // CsvWriter writeCsv;
562 try
563 {
564 if(connection.getAutoCommit())
565 writeCsv = new CsvWriter(
566 fileName,
567 connection.getSeperator(),
568 connection.getExtension(),
569 connection.getMaxFileSize(),
570 connection.getCharset(),
571 connection.getUseQuotes(),
572 connection.getUseQuotesEscape()
573 );
574 else{
575 writeCsv.setFileName(fileName);
576 writeCsv.fillTableColumnNames();
577 }
578
579 String[] xxx = parser.getColumnNames();
580 String[] yyy = writeCsv.getColumnNames();
581 boolean isOK = true;
582 for(int i=0; i< xxx.length; i++) {
583 if(!xxx[i].endsWith("*")) {
584 out:
585 for(int j=0; j< yyy.length; j++) {
586 if(xxx[i].equalsIgnoreCase( yyy[j] )) {
587 isOK=true;
588 break out;
589 }
590 else
591 isOK=false;
592 }
593 if(!isOK)
594 throw new SQLException("Column '" + xxx[i] + "' not found.");
595 }
596 }
597 if(!writeCsv.updateFields(parser.columnNames, parser.columnValues, parser.columnWhereNames, parser.columnWhereValues))
598 updated = -1;
599 }
600 catch (Exception e)
601 {
602 throw new SQLException("Error reading data file. Message was: " + e);
603 }
604
605 }
606 return updated;
607
608 }
609
610
611 /***
612 * Releases this <code>Statement</code> object's database
613 * and JDBC resources immediately instead of waiting for
614 * this to happen when it is automatically closed.
615 * It is generally good practice to release resources as soon as
616 * you are finished with them to avoid tying up database
617 * resources.
618 * <P>
619 * Calling the method <code>close</code> on a <code>Statement</code>
620 * object that is already closed has no effect.
621 * <P>
622 * <B>Note:</B> A <code>Statement</code> object is automatically closed
623 * when it is garbage collected. When a <code>Statement</code> object is
624 * closed, its current <code>ResultSet</code> object, if one exists, is
625 * also closed.
626 *
627 * @exception SQLException if a database access error occurs
628 */
629 public void close() throws SQLException {
630 // close all result sets
631 for(Enumeration i = resultSets.elements(); i.hasMoreElements(); ) {
632 CsvResultSet resultSet = (CsvResultSet) i.nextElement();
633 resultSet.close();
634 }
635 try {
636 if(this.writeCsv != null)
637 this.writeCsv.close();
638 }
639 catch(Exception e) {
640 e.printStackTrace();
641 throw new SQLException(e.getMessage());
642 }
643 }
644
645 /***
646 *Description of the Method
647 *
648 * @exception SQLException Description of Exception
649 * @since
650 */
651 public void cancel() throws SQLException
652 {
653 throw new SQLException("Not Supported !");
654 }
655
656
657 /***
658 *Description of the Method
659 *
660 * @exception SQLException Description of Exception
661 * @since
662 */
663 public void clearWarnings() throws SQLException
664 {
665 throw new SQLException("Not Supported !");
666 }
667
668
669 /***
670 *Description of the Method
671 *
672 * @param sql Description of Parameter
673 * @return Description of the Returned Value
674 * @exception SQLException Description of Exception
675 * @since
676 */
677 public boolean execute(String sql) throws SQLException
678 {
679 CsvSqlParser parser = new CsvSqlParser();
680 if( binaryStreamParameters.size() != 0 )
681 parser.setBinaryStreamList( binaryStreamParameters );
682 this.sql = sql;
683 try
684 {
685 parser.parse(this);
686 }
687 catch (Exception e)
688 {
689 throw new SQLException("Syntax Error. " + e.getMessage());
690 }
691 if(parser.sqlType.equals(parser.SELECT))
692 throw new SQLException("Not supported SELECT statement - use executeQuery method");
693 else if (parser.sqlType.equals(parser.INSERT))
694 executeUpdate(sql);
695 else if (parser.sqlType.equals(parser.CREATE_TABLE)) {
696 String fileName = connection.getPath() + parser.getTableName() + connection.getExtension();
697 File checkFile = new File(fileName);
698
699 if (checkFile.exists())
700 {
701 throw new SQLException("Data file '" + fileName + "'already exists !");
702 }
703
704 // CsvWriter writeCsv;
705 try
706 {
707 if(connection.getAutoCommit())
708 writeCsv = new CsvWriter(
709 fileName,
710 connection.getSeperator(),
711 connection.getExtension(),
712 connection.getMaxFileSize(),
713 connection.getCharset(),
714 connection.getUseQuotes(),
715 connection.getUseQuotesEscape()
716 );
717 else{
718 writeCsv.setFileName(fileName);
719 writeCsv.fillTableColumnNames();
720 }
721
722 writeCsv.createTable(parser.columnNames, fileName);
723 }
724 catch (Exception e)
725 {
726 throw new SQLException("Error reading data file. Message was: " + e);
727 }
728 }
729 return true;
730
731 }
732
733 /***
734 * Set String as parameter in sql statement.
735 * @param parameterIndex
736 * @param value
737 * @throws SQLException
738 */
739 public void setString(int parameterIndex, String value) throws SQLException {
740 if( value == null ) {
741 CsvDriver.log("value = null object");
742 parameters.set(parameterIndex - 1, value);
743 } else {
744 value = Utils.replaceAll(value, "'", CsvSqlParser.QUOTE_ESCAPE);
745 CsvDriver.log("value = " + value);
746 parameters.set(parameterIndex - 1, "'" + value + "'");
747 }
748 }
749
750
751 /***
752 *
753 * @param parameterIndex
754 * @param value
755 * @throws SQLException
756 */
757 public void setBytes(int parameterIndex, byte[] value) throws SQLException {
758 binaryStreamParameters.add(Utils.bytesToHexString(value));
759 String paramName = CsvSqlParser.BINARY_STREAM_OBJECT+""+binaryStreamParameters.size();
760 parameters.set(parameterIndex-1, paramName);
761 }
762
763 /***
764 *Adds a feature to the Batch attribute of the CsvStatement object
765 *
766 * @param p0 The feature to be added to the Batch attribute
767 * @exception SQLException Description of Exception
768 * @since
769 */
770 public void addBatch(String p0) throws SQLException
771 {
772 throw new SQLException("Not Supported !");
773 }
774
775
776 /***
777 *Description of the Method
778 *
779 * @exception SQLException Description of Exception
780 * @since
781 */
782 public void clearBatch() throws SQLException
783 {
784 throw new SQLException("Not Supported !");
785 }
786
787
788 /***
789 *Description of the Method
790 *
791 * @return Description of the Returned Value
792 * @exception SQLException Description of Exception
793 * @since
794 */
795 public int[] executeBatch() throws SQLException
796 {
797 throw new SQLException("Not Supported !");
798 }
799
800 //---------------------------------------------------------------------
801 // JDBC 3.0
802 //---------------------------------------------------------------------
803
804 public boolean getMoreResults(int current) throws SQLException {
805 throw new UnsupportedOperationException("Statement.getMoreResults(int) unsupported");
806 }
807
808 public ResultSet getGeneratedKeys() throws SQLException {
809 throw new UnsupportedOperationException("Statement.getGeneratedKeys() unsupported");
810 }
811
812 public int executeUpdate(String sql, int autoGeneratedKeys) throws SQLException {
813 throw new UnsupportedOperationException("Statement.executeUpdate(String,int) unsupported");
814 }
815
816 public int executeUpdate(String sql, int[] columnIndexes) throws SQLException {
817 throw new UnsupportedOperationException("Statement.executeUpdate(String,int[]) unsupported");
818 }
819
820 public int executeUpdate(String sql, String[] columnNames) throws SQLException {
821 throw new UnsupportedOperationException("Statement.executeUpdate(String,String[]) unsupported");
822 }
823
824 public boolean execute(String sql, int autoGeneratedKeys) throws SQLException {
825 throw new UnsupportedOperationException("Statement.execute(String,int) unsupported");
826 }
827
828 public boolean execute(String sql, int[] columnIndexes) throws SQLException {
829 throw new UnsupportedOperationException("Statement.execute(String,int[]) unsupported");
830 }
831
832 public boolean execute(String sql, String[] columnNames) throws SQLException {
833 throw new UnsupportedOperationException("Statement.execute(String,String[]) unsupported");
834 }
835
836 public int getResultSetHoldability() throws SQLException {
837 throw new UnsupportedOperationException("Statement.getResultSetHoldability() unsupported");
838 }
839
840
841
842 public ResultSet executeQuery() throws SQLException {
843 if( !prepareSql())
844 throw new SQLException("Error with prepared statement !");
845 return executeQuery(this.sqlPrepared);
846
847 }
848 public int executeUpdate() throws SQLException {
849 if( !prepareSql())
850 throw new SQLException("Error with prepared statement !");
851 executeUpdate(this.sqlPrepared);
852 return 0;
853 }
854
855
856
857
858
859 public void setNull(int parameterIndex, int sqlType) throws SQLException {
860 this.setString(parameterIndex, null );
861 }
862
863 public void setBoolean(int parameterIndex, boolean value) throws SQLException {
864 this.setString(parameterIndex, String.valueOf(value) );
865 }
866
867 public void setByte(int parameterIndex, byte value) throws SQLException {
868 this.setString(parameterIndex, String.valueOf(value) );
869 }
870
871 public void setShort(int parameterIndex, short value) throws SQLException {
872 this.setString(parameterIndex, String.valueOf(value) );
873 }
874
875 public void setInt(int parameterIndex, int value) throws SQLException {
876 this.setString(parameterIndex, String.valueOf(value) );
877 }
878
879 public void setLong(int parameterIndex, long value) throws SQLException {
880 this.setString(parameterIndex, String.valueOf(value) );
881 }
882
883 public void setFloat(int parameterIndex, float value) throws SQLException {
884 this.setString(parameterIndex, String.valueOf(value) );
885 }
886
887 public void setDouble(int parameterIndex, double value) throws SQLException {
888 this.setString(parameterIndex, String.valueOf(value) );
889 }
890
891 public void setBigDecimal(int parameterIndex, BigDecimal value) throws SQLException {
892 if(value == null) {
893 this.setString( parameterIndex, value.toString() );
894 } else {
895 this.setString( parameterIndex, "" );
896 }
897 }
898
899 public void setDate(int parameterIndex, Date value) throws SQLException {
900 if(value == null) {
901 this.setString( parameterIndex, value.toString() );
902 } else {
903 this.setString( parameterIndex, "" );
904 }
905 }
906
907 public void setTime(int parameterIndex, Time value) throws SQLException {
908 if(value == null) {
909 this.setString( parameterIndex, value.toString() );
910 } else {
911 this.setString( parameterIndex, "" );
912 }
913 }
914
915 public void setTimestamp(int parameterIndex, Timestamp value) throws SQLException {
916 if(value == null) {
917 this.setString( parameterIndex, value.toString() );
918 } else {
919 this.setString( parameterIndex, "" );
920 }
921 }
922
923 public void setAsciiStream(int parameterIndex, InputStream x, int length) throws SQLException {
924 /***@todo Implement this java.sql.PreparedStatement method*/
925 throw new java.lang.UnsupportedOperationException("Method setAsciiStream() not yet implemented.");
926 }
927 public void setUnicodeStream(int parameterIndex, InputStream x, int length) throws SQLException {
928 /***@todo Implement this java.sql.PreparedStatement method*/
929 throw new java.lang.UnsupportedOperationException("Method setUnicodeStream() not yet implemented.");
930 }
931
932 public void clearParameters() throws SQLException {
933 this.sqlPrepared = this.sqlForPrepare;
934 for(int i = 0; i < parameters.size(); i++)
935 parameters.set(i, null);
936 }
937 public void setObject(int parameterIndex, Object x, int targetSqlType, int scale) throws SQLException {
938 /***@todo Implement this java.sql.PreparedStatement method*/
939 throw new java.lang.UnsupportedOperationException("Method setObject() not yet implemented.");
940 }
941 public void setObject(int parameterIndex, Object x, int targetSqlType) throws SQLException {
942 /***@todo Implement this java.sql.PreparedStatement method*/
943 throw new java.lang.UnsupportedOperationException("Method setObject() not yet implemented.");
944 }
945 public void setObject(int parameterIndex, Object x) throws SQLException {
946 if( x == null )
947 setString(parameterIndex, null);
948 else
949 setString( parameterIndex, x.toString() );
950 }
951 public boolean execute() throws SQLException {
952 /***@todo Implement this java.sql.PreparedStatement method*/
953 throw new java.lang.UnsupportedOperationException("Method execute() not yet implemented.");
954 }
955 public void addBatch() throws SQLException {
956 /***@todo Implement this java.sql.PreparedStatement method*/
957 throw new java.lang.UnsupportedOperationException("Method addBatch() not yet implemented.");
958 }
959 public void setCharacterStream(int parameterIndex, Reader reader, int length) throws SQLException {
960 /***@todo Implement this java.sql.PreparedStatement method*/
961 throw new java.lang.UnsupportedOperationException("Method setCharacterStream() not yet implemented.");
962 }
963 public void setRef(int i, Ref x) throws SQLException {
964 /***@todo Implement this java.sql.PreparedStatement method*/
965 throw new java.lang.UnsupportedOperationException("Method setRef() not yet implemented.");
966 }
967
968 public void setClob(int i, Clob x) throws SQLException {
969 /***@todo Implement this java.sql.PreparedStatement method*/
970 throw new java.lang.UnsupportedOperationException("Method setClob() not yet implemented.");
971 }
972 public void setArray(int i, Array x) throws SQLException {
973 /***@todo Implement this java.sql.PreparedStatement method*/
974 throw new java.lang.UnsupportedOperationException("Method setArray() not yet implemented.");
975 }
976 public ResultSetMetaData getMetaData() throws SQLException {
977 /***@todo Implement this java.sql.PreparedStatement method*/
978 throw new java.lang.UnsupportedOperationException("Method getMetaData() not yet implemented.");
979 }
980 public void setDate(int parameterIndex, Date x, Calendar cal) throws SQLException {
981 /***@todo Implement this java.sql.PreparedStatement method*/
982 throw new java.lang.UnsupportedOperationException("Method setDate() not yet implemented.");
983 }
984 public void setTime(int parameterIndex, Time x, Calendar cal) throws SQLException {
985 /***@todo Implement this java.sql.PreparedStatement method*/
986 throw new java.lang.UnsupportedOperationException("Method setTime() not yet implemented.");
987 }
988 public void setTimestamp(int parameterIndex, Timestamp x, Calendar cal) throws SQLException {
989 /***@todo Implement this java.sql.PreparedStatement method*/
990 throw new java.lang.UnsupportedOperationException("Method setTimestamp() not yet implemented.");
991 }
992 public void setNull(int paramIndex, int sqlType, String typeName) throws SQLException {
993 this.setString(paramIndex, null );
994 }
995
996 public void setURL(int parameterIndex, URL x) throws SQLException {
997 /***@todo Implement this java.sql.PreparedStatement method*/
998 throw new java.lang.UnsupportedOperationException(
999 "Method setURL() not yet implemented.");
1000 }
1001
1002 public ParameterMetaData getParameterMetaData() throws SQLException {
1003 /***@todo Implement this java.sql.PreparedStatement method*/
1004 throw new java.lang.UnsupportedOperationException(
1005 "Method getParameterMetaData() not yet implemented.");
1006 }
1007
1008 public void setBinaryStream(int parameterIndex, InputStream value, int length) throws
1009 SQLException {
1010 try {
1011 String hex = Utils.streamToHexString(value);
1012 this.setBytes(parameterIndex,Utils.hexStringToBytes(hex));
1013 } catch (Exception e) {
1014 throw new SQLException("Error in setBinaryStream(): "+e.getMessage());
1015 }
1016 }
1017
1018 public void setBlob(int parameterIndex, Blob value) throws SQLException {
1019 /***@todo Implement this java.sql.PreparedStatement method*/
1020 throw new java.lang.UnsupportedOperationException(
1021 "Method setBlob() not yet implemented.");
1022 }
1023
1024 public String getSqlStatement() {
1025 return sql;
1026 }
1027
1028 }
This page was automatically generated by Maven