0001: /**
0002: Copyright (C) 2002-2003 Together
0003:
0004: This library is free software; you can redistribute it and/or
0005: modify it under the terms of the GNU Lesser General Public
0006: License as published by the Free Software Foundation; either
0007: version 2.1 of the License, or (at your option) any later version.
0008:
0009: This library is distributed in the hope that it will be useful,
0010: but WITHOUT ANY WARRANTY; without even the implied warranty of
0011: MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
0012: Lesser General Public License for more details.
0013:
0014: You should have received a copy of the GNU Lesser General Public
0015: License along with this library; if not, write to the Free Software
0016: Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
0017:
0018: */package org.relique.jdbc.csv;
0019:
0020: import java.io.File;
0021: import java.io.InputStream;
0022: import java.io.Reader;
0023: import java.math.BigDecimal;
0024: import java.net.URL;
0025: import java.sql.Array;
0026: import java.sql.Blob;
0027: import java.sql.Clob;
0028: import java.sql.Connection;
0029: import java.sql.Date;
0030: import java.sql.DriverManager;
0031: import java.sql.NClob;
0032: import java.sql.ParameterMetaData;
0033: import java.sql.PreparedStatement;
0034: import java.sql.Ref;
0035: import java.sql.ResultSet;
0036: import java.sql.ResultSetMetaData;
0037: import java.sql.RowId;
0038: import java.sql.SQLException;
0039: import java.sql.SQLWarning;
0040: import java.sql.SQLXML;
0041: import java.sql.Time;
0042: import java.sql.Timestamp;
0043: import java.util.ArrayList;
0044: import java.util.Calendar;
0045: import java.util.Enumeration;
0046: import java.util.Vector;
0047:
0048: /**
0049: * This class implements the PreparedStatement interface for the CsvJdbc driver.
0050: *
0051: * @author Zoran Milakovic
0052: */
0053: public class CsvPreparedStatement implements PreparedStatement {
0054:
0055: private CsvConnection connection;
0056: private Vector resultSets = new Vector();
0057: private String sqlForPrepare = "";
0058: private String sqlPrepared = "";
0059: private int paramCount = 0;
0060: private ArrayList parameters = new ArrayList();
0061: private ArrayList binaryStreamParameters = new ArrayList();
0062: private CsvWriter writeCsv;
0063: /** Name used for prepared statement parameters */
0064: public static String PREPARE_SEPARATOR = "~@#NEXTPARAMETER#@~";
0065: private String sql;
0066:
0067: public CsvPreparedStatement(CsvConnection connection,
0068: String preparedSql) {
0069: DriverManager.println("CsvJdbc - CsvStatement() - connection="
0070: + connection);
0071: this .sqlForPrepare = preparedSql;
0072: this .sqlPrepared = preparedSql;
0073: this .paramCount = countParameters(preparedSql);
0074: for (int i = 0; i < paramCount; i++)
0075: parameters.add(null);
0076: this .connection = connection;
0077: try {
0078: if (!connection.getAutoCommit())
0079: writeCsv = new CsvWriter(null, connection
0080: .getSeperator(), connection.getExtension(),
0081: connection.getMaxFileSize(), connection
0082: .getCharset(), connection
0083: .getUseQuotes(), connection
0084: .getUseQuotesEscape());
0085: } catch (Exception ex) {
0086: ex.printStackTrace();
0087: }
0088: }
0089:
0090: private int countParameters(String sql) {
0091: int count = 0;
0092: int index = sql.indexOf(PREPARE_SEPARATOR);
0093: while (index != -1) {
0094: count++;
0095: sql = sql.substring(index + 1);
0096: index = sql.indexOf(PREPARE_SEPARATOR);
0097: }
0098: return count;
0099: }
0100:
0101: private boolean prepareSql() throws SQLException {
0102: boolean retVal = true;
0103: for (int i = 0; i < parameters.size(); i++) {
0104: int index = sqlPrepared.indexOf(PREPARE_SEPARATOR);
0105: String val;
0106: if (index != -1) {
0107: if (parameters.get(i) == null)
0108: val = "null";
0109: else
0110: val = parameters.get(i).toString();
0111: sqlPrepared = sqlPrepared.substring(0, index)
0112: + val
0113: + sqlPrepared.substring(index
0114: + PREPARE_SEPARATOR.length());
0115: }
0116: }
0117: if (sqlPrepared.indexOf(PREPARE_SEPARATOR) != -1)
0118: throw new SQLException(
0119: "All ? in prepared query has to be replaced with values.");
0120: else if (parameters.size() < this .paramCount)
0121: throw new SQLException(
0122: "Number of setted parameters is less than number of parameters in statement.");
0123: else if (parameters.size() > this .paramCount)
0124: throw new SQLException(
0125: "Number of setted parameters is greater than number of parameters in statement.");
0126:
0127: return retVal;
0128: }
0129:
0130: /**
0131: *Sets the maxFieldSize attribute of the CsvStatement object
0132: *
0133: * @param p0 The new maxFieldSize value
0134: * @exception SQLException Description of Exception
0135: * @since
0136: */
0137: public void setMaxFieldSize(int p0) throws SQLException {
0138: throw new SQLException("Not Supported !");
0139: }
0140:
0141: /**
0142: *Sets the maxRows attribute of the CsvStatement object
0143: *
0144: * @param p0 The new maxRows value
0145: * @exception SQLException Description of Exception
0146: * @since
0147: */
0148: public void setMaxRows(int p0) throws SQLException {
0149: throw new SQLException("Not Supported !");
0150: }
0151:
0152: /**
0153: *Sets the escapeProcessing attribute of the CsvStatement object
0154: *
0155: * @param p0 The new escapeProcessing value
0156: * @exception SQLException Description of Exception
0157: * @since
0158: */
0159: public void setEscapeProcessing(boolean p0) throws SQLException {
0160: throw new SQLException("Not Supported !");
0161: }
0162:
0163: /**
0164: *Sets the queryTimeout attribute of the CsvStatement object
0165: *
0166: * @param p0 The new queryTimeout value
0167: * @exception SQLException Description of Exception
0168: * @since
0169: */
0170: public void setQueryTimeout(int p0) throws SQLException {
0171: throw new SQLException("Not Supported !");
0172: }
0173:
0174: /**
0175: *Sets the cursorName attribute of the CsvStatement object
0176: *
0177: * @param p0 The new cursorName value
0178: * @exception SQLException Description of Exception
0179: * @since
0180: */
0181: public void setCursorName(String p0) throws SQLException {
0182: throw new SQLException("Not Supported !");
0183: }
0184:
0185: /**
0186: *Sets the fetchDirection attribute of the CsvStatement object
0187: *
0188: * @param p0 The new fetchDirection value
0189: * @exception SQLException Description of Exception
0190: * @since
0191: */
0192: public void setFetchDirection(int p0) throws SQLException {
0193: throw new SQLException("Not Supported !");
0194: }
0195:
0196: /**
0197: *Sets the fetchSize attribute of the CsvStatement object
0198: *
0199: * @param p0 The new fetchSize value
0200: * @exception SQLException Description of Exception
0201: * @since
0202: */
0203: public void setFetchSize(int p0) throws SQLException {
0204: throw new SQLException("Not Supported !");
0205: }
0206:
0207: /**
0208: *Gets the maxFieldSize attribute of the CsvStatement object
0209: *
0210: * @return The maxFieldSize value
0211: * @exception SQLException Description of Exception
0212: * @since
0213: */
0214: public int getMaxFieldSize() throws SQLException {
0215: throw new SQLException("Not Supported !");
0216: }
0217:
0218: /**
0219: *Gets the maxRows attribute of the CsvStatement object
0220: *
0221: * @return The maxRows value
0222: * @exception SQLException Description of Exception
0223: * @since
0224: */
0225: public int getMaxRows() throws SQLException {
0226: throw new SQLException("Not Supported !");
0227: }
0228:
0229: /**
0230: *Gets the queryTimeout attribute of the CsvStatement object
0231: *
0232: * @return The queryTimeout value
0233: * @exception SQLException Description of Exception
0234: * @since
0235: */
0236: public int getQueryTimeout() throws SQLException {
0237: throw new SQLException("Not Supported !");
0238: }
0239:
0240: /**
0241: *Gets the warnings attribute of the CsvStatement object
0242: *
0243: * @return The warnings value
0244: * @exception SQLException Description of Exception
0245: * @since
0246: */
0247: public SQLWarning getWarnings() throws SQLException {
0248: throw new SQLException("Not Supported !");
0249: }
0250:
0251: /**
0252: *Gets the resultSet attribute of the CsvStatement object
0253: *
0254: * @return The resultSet value
0255: * @exception SQLException Description of Exception
0256: * @since
0257: */
0258: public ResultSet getResultSet() throws SQLException {
0259: throw new SQLException("Not Supported !");
0260: }
0261:
0262: /**
0263: *Gets the updateCount attribute of the CsvStatement object
0264: *
0265: * @return The updateCount value
0266: * @exception SQLException Description of Exception
0267: * @since
0268: */
0269: public int getUpdateCount() throws SQLException {
0270: throw new SQLException("Not Supported !");
0271: }
0272:
0273: /**
0274: *Gets the moreResults attribute of the CsvStatement object
0275: *
0276: * @return The moreResults value
0277: * @exception SQLException Description of Exception
0278: * @since
0279: */
0280: public boolean getMoreResults() throws SQLException {
0281: throw new SQLException("Not Supported !");
0282: }
0283:
0284: /**
0285: *Gets the fetchDirection attribute of the CsvStatement object
0286: *
0287: * @return The fetchDirection value
0288: * @exception SQLException Description of Exception
0289: * @since
0290: */
0291: public int getFetchDirection() throws SQLException {
0292: throw new SQLException("Not Supported !");
0293: }
0294:
0295: /**
0296: *Gets the fetchSize attribute of the CsvStatement object
0297: *
0298: * @return The fetchSize value
0299: * @exception SQLException Description of Exception
0300: * @since
0301: */
0302: public int getFetchSize() throws SQLException {
0303: throw new SQLException("Not Supported !");
0304: }
0305:
0306: /**
0307: *Gets the resultSetConcurrency attribute of the CsvStatement object
0308: *
0309: * @return The resultSetConcurrency value
0310: * @exception SQLException Description of Exception
0311: * @since
0312: */
0313: public int getResultSetConcurrency() throws SQLException {
0314: throw new SQLException("Not Supported !");
0315: }
0316:
0317: /**
0318: *Gets the resultSetType attribute of the CsvStatement object
0319: *
0320: * @return The resultSetType value
0321: * @exception SQLException Description of Exception
0322: * @since
0323: */
0324: public int getResultSetType() throws SQLException {
0325: throw new SQLException("Not Supported !");
0326: }
0327:
0328: /**
0329: *Gets the connection attribute of the CsvStatement object
0330: *
0331: * @return The connection value
0332: * @exception SQLException Description of Exception
0333: * @since
0334: */
0335: public Connection getConnection() throws SQLException {
0336: return connection;
0337: }
0338:
0339: /**
0340: *Description of the Method
0341: *
0342: * @param sql Description of Parameter
0343: * @return Description of the Returned Value
0344: * @exception SQLException Description of Exception
0345: * @since
0346: */
0347: public ResultSet executeQuery(String sql) throws SQLException {
0348: DriverManager
0349: .println("CsvJdbc - CsvStatement:executeQuery() - sql= "
0350: + sql);
0351: CsvSqlParser parser = new CsvSqlParser();
0352: if (binaryStreamParameters.size() != 0)
0353: parser.setBinaryStreamList(binaryStreamParameters);
0354:
0355: this .sql = sql;
0356: try {
0357: parser.parse(this );
0358: } catch (Exception e) {
0359: throw new SQLException("Syntax Error. " + e.getMessage());
0360: }
0361:
0362: String fileName = connection.getPath() + parser.getTableName()
0363: + connection.getExtension();
0364: File checkFile = new File(fileName);
0365: if (!checkFile.exists()) {
0366: throw new SQLException("Cannot open data file '" + fileName
0367: + "' !");
0368: }
0369:
0370: if (!checkFile.canRead()) {
0371: throw new SQLException("Data file '" + fileName
0372: + "' not readable !");
0373: }
0374: CsvReader reader;
0375: try {
0376: reader = new CsvReader(fileName, connection.getSeperator(),
0377: connection.isSuppressHeaders(), connection
0378: .getCharset(), connection.getExtension(),
0379: connection.getLineBreakEscape(),
0380: // connection.getDoubleQuotesEscape(),
0381: connection.getCarriageReturnEscape(), connection
0382: .isTrimString());
0383: String[] xxx = parser.getColumnNames();
0384: String[] yyy = reader.getColumnNames();
0385: boolean isOK = true;
0386: for (int i = 0; i < xxx.length; i++) {
0387: if (!xxx[i].endsWith("*")) {
0388: out: for (int j = 0; j < yyy.length; j++) {
0389: if (xxx[i].equalsIgnoreCase(yyy[j])) {
0390: isOK = true;
0391: break out;
0392: } else
0393: isOK = false;
0394: }
0395: if (!isOK)
0396: throw new SQLException("Column '" + xxx[i]
0397: + "' not found.");
0398: }
0399: }
0400: } catch (Exception e) {
0401: throw new SQLException(
0402: "Error reading data file. Message was: " + e);
0403: }
0404: CsvResultSet resultSet = new CsvResultSet(this , reader, parser
0405: .getTableName(), parser.getColumnNames(), parser
0406: .getWhereColumnNames(), parser.getWhereColumnValues(),
0407: reader.getColumnTypes());
0408: resultSets.add(resultSet);
0409: return resultSet;
0410: }
0411:
0412: /**
0413: *Description of the Method
0414: *
0415: * @param sql Description of Parameter
0416: * @return Description of the Returned Value
0417: * @exception SQLException Description of Exception
0418: * @since
0419: */
0420: public int executeUpdate(String sql) throws SQLException {
0421: int updated = 0;
0422: DriverManager
0423: .println("CsvJdbc - CsvStatement:executeUpdate() - sql= "
0424: + sql);
0425: CsvSqlParser parser = new CsvSqlParser();
0426: if (binaryStreamParameters.size() != 0)
0427: parser.setBinaryStreamList(binaryStreamParameters);
0428: this .sql = sql;
0429: try {
0430: parser.parse(this );
0431: } catch (Exception e) {
0432: throw new SQLException("Syntax Error. " + e.getMessage());
0433: }
0434: if (parser.sqlType.equals(parser.SELECT))
0435: throw new SQLException(
0436: "Not supported SELECT statement - use executeQuery method");
0437: else if (parser.sqlType.equals(parser.CREATE_TABLE)) {
0438: throw new SQLException(
0439: "Not supported CREATE TABLE statement - use execute method");
0440: } else if (parser.sqlType.equals(parser.INSERT)) {
0441: String fileName = connection.getPath()
0442: + parser.getTableName() + connection.getExtension();
0443: File checkFile = new File(fileName);
0444:
0445: if (!checkFile.exists()) {
0446: throw new SQLException("Cannot open data file '"
0447: + fileName + "' !");
0448: }
0449:
0450: if (!checkFile.canWrite()) {
0451: throw new SQLException("Data file '" + fileName
0452: + "' is read only !");
0453: }
0454: // CsvWriter writeCsv;
0455: try {
0456: if (connection.getAutoCommit())
0457: writeCsv = new CsvWriter(fileName, connection
0458: .getSeperator(), connection.getExtension(),
0459: connection.getMaxFileSize(), connection
0460: .getCharset(), connection
0461: .getUseQuotes(), connection
0462: .getUseQuotesEscape());
0463: else {
0464: writeCsv.setFileName(fileName);
0465: writeCsv.fillTableColumnNames();
0466: }
0467:
0468: String[] xxx = parser.getColumnNames();
0469: String[] yyy = writeCsv.getColumnNames();
0470: boolean isOK = true;
0471: for (int i = 0; i < xxx.length; i++) {
0472: if (!xxx[i].endsWith("*")) {
0473: out: for (int j = 0; j < yyy.length; j++) {
0474: if (xxx[i].equalsIgnoreCase(yyy[j])) {
0475: isOK = true;
0476: break out;
0477: } else
0478: isOK = false;
0479: }
0480: if (!isOK)
0481: throw new SQLException("Column '" + xxx[i]
0482: + "' not found.");
0483: }
0484: }
0485: writeCsv.newLine(parser.columnNames,
0486: parser.columnValues);
0487:
0488: } catch (Exception e) {
0489: e.printStackTrace();
0490: throw new SQLException(
0491: "Error reading data file. Message was: " + e);
0492: }
0493:
0494: } else if (parser.sqlType.equals(parser.UPDATE)) {
0495:
0496: String fileName = connection.getPath()
0497: + parser.getTableName() + connection.getExtension();
0498: File checkFile = new File(fileName);
0499:
0500: if (!checkFile.exists()) {
0501: throw new SQLException("Cannot open data file '"
0502: + fileName + "' !");
0503: }
0504:
0505: if (!checkFile.canWrite()) {
0506: throw new SQLException("Data file '" + fileName
0507: + "' is read only !");
0508: }
0509: // CsvWriter writeCsv;
0510: try {
0511: if (connection.getAutoCommit())
0512: writeCsv = new CsvWriter(fileName, connection
0513: .getSeperator(), connection.getExtension(),
0514: connection.getMaxFileSize(), connection
0515: .getCharset(), connection
0516: .getUseQuotes(), connection
0517: .getUseQuotesEscape());
0518: else {
0519: writeCsv.setFileName(fileName);
0520: writeCsv.fillTableColumnNames();
0521: }
0522:
0523: String[] xxx = parser.getColumnNames();
0524: String[] yyy = writeCsv.getColumnNames();
0525: boolean isOK = true;
0526: for (int i = 0; i < xxx.length; i++) {
0527: if (!xxx[i].endsWith("*")) {
0528: out: for (int j = 0; j < yyy.length; j++) {
0529: if (xxx[i].equalsIgnoreCase(yyy[j])) {
0530: isOK = true;
0531: break out;
0532: } else
0533: isOK = false;
0534: }
0535: if (!isOK)
0536: throw new SQLException("Column '" + xxx[i]
0537: + "' not found.");
0538: }
0539: }
0540: if (!writeCsv.updateFields(parser.columnNames,
0541: parser.columnValues, parser.columnWhereNames,
0542: parser.columnWhereValues))
0543: updated = -1;
0544: } catch (Exception e) {
0545: throw new SQLException(
0546: "Error reading data file. Message was: " + e);
0547: }
0548:
0549: }
0550: return updated;
0551:
0552: }
0553:
0554: /**
0555: * Releases this <code>Statement</code> object's database
0556: * and JDBC resources immediately instead of waiting for
0557: * this to happen when it is automatically closed.
0558: * It is generally good practice to release resources as soon as
0559: * you are finished with them to avoid tying up database
0560: * resources.
0561: * <P>
0562: * Calling the method <code>close</code> on a <code>Statement</code>
0563: * object that is already closed has no effect.
0564: * <P>
0565: * <B>Note:</B> A <code>Statement</code> object is automatically closed
0566: * when it is garbage collected. When a <code>Statement</code> object is
0567: * closed, its current <code>ResultSet</code> object, if one exists, is
0568: * also closed.
0569: *
0570: * @exception SQLException if a database access error occurs
0571: */
0572: public void close() throws SQLException {
0573: // close all result sets
0574: for (Enumeration i = resultSets.elements(); i.hasMoreElements();) {
0575: CsvResultSet resultSet = (CsvResultSet) i.nextElement();
0576: resultSet.close();
0577: }
0578: try {
0579: if (this .writeCsv != null)
0580: this .writeCsv.close();
0581: } catch (Exception e) {
0582: e.printStackTrace();
0583: throw new SQLException(e.getMessage());
0584: }
0585: }
0586:
0587: /**
0588: *Description of the Method
0589: *
0590: * @exception SQLException Description of Exception
0591: * @since
0592: */
0593: public void cancel() throws SQLException {
0594: throw new SQLException("Not Supported !");
0595: }
0596:
0597: /**
0598: *Description of the Method
0599: *
0600: * @exception SQLException Description of Exception
0601: * @since
0602: */
0603: public void clearWarnings() throws SQLException {
0604: throw new SQLException("Not Supported !");
0605: }
0606:
0607: /**
0608: *Description of the Method
0609: *
0610: * @param sql Description of Parameter
0611: * @return Description of the Returned Value
0612: * @exception SQLException Description of Exception
0613: * @since
0614: */
0615: public boolean execute(String sql) throws SQLException {
0616: CsvSqlParser parser = new CsvSqlParser();
0617: if (binaryStreamParameters.size() != 0)
0618: parser.setBinaryStreamList(binaryStreamParameters);
0619: this .sql = sql;
0620: try {
0621: parser.parse(this );
0622: } catch (Exception e) {
0623: throw new SQLException("Syntax Error. " + e.getMessage());
0624: }
0625: if (parser.sqlType.equals(parser.SELECT))
0626: throw new SQLException(
0627: "Not supported SELECT statement - use executeQuery method");
0628: else if (parser.sqlType.equals(parser.INSERT))
0629: executeUpdate(sql);
0630: else if (parser.sqlType.equals(parser.CREATE_TABLE)) {
0631: String fileName = connection.getPath()
0632: + parser.getTableName() + connection.getExtension();
0633: File checkFile = new File(fileName);
0634:
0635: if (checkFile.exists()) {
0636: throw new SQLException("Data file '" + fileName
0637: + "'already exists !");
0638: }
0639:
0640: // CsvWriter writeCsv;
0641: try {
0642: if (connection.getAutoCommit())
0643: writeCsv = new CsvWriter(fileName, connection
0644: .getSeperator(), connection.getExtension(),
0645: connection.getMaxFileSize(), connection
0646: .getCharset(), connection
0647: .getUseQuotes(), connection
0648: .getUseQuotesEscape());
0649: else {
0650: writeCsv.setFileName(fileName);
0651: writeCsv.fillTableColumnNames();
0652: }
0653:
0654: writeCsv.createTable(parser.columnNames, fileName);
0655: } catch (Exception e) {
0656: throw new SQLException(
0657: "Error reading data file. Message was: " + e);
0658: }
0659: }
0660: return true;
0661:
0662: }
0663:
0664: /**
0665: * Set String as parameter in sql statement.
0666: * @param parameterIndex
0667: * @param value
0668: * @throws SQLException
0669: */
0670: public void setString(int parameterIndex, String value)
0671: throws SQLException {
0672: if (value == null) {
0673: CsvDriver.log("value = null object");
0674: parameters.set(parameterIndex - 1, value);
0675: } else {
0676: value = Utils.replaceAll(value, "'",
0677: CsvSqlParser.QUOTE_ESCAPE);
0678: CsvDriver.log("value = " + value);
0679: parameters.set(parameterIndex - 1, "'" + value + "'");
0680: }
0681: }
0682:
0683: /**
0684: *
0685: * @param parameterIndex
0686: * @param value
0687: * @throws SQLException
0688: */
0689: public void setBytes(int parameterIndex, byte[] value)
0690: throws SQLException {
0691: binaryStreamParameters.add(Utils.bytesToHexString(value));
0692: String paramName = CsvSqlParser.BINARY_STREAM_OBJECT + ""
0693: + binaryStreamParameters.size();
0694: parameters.set(parameterIndex - 1, paramName);
0695: }
0696:
0697: /**
0698: *Adds a feature to the Batch attribute of the CsvStatement object
0699: *
0700: * @param p0 The feature to be added to the Batch attribute
0701: * @exception SQLException Description of Exception
0702: * @since
0703: */
0704: public void addBatch(String p0) throws SQLException {
0705: throw new SQLException("Not Supported !");
0706: }
0707:
0708: /**
0709: *Description of the Method
0710: *
0711: * @exception SQLException Description of Exception
0712: * @since
0713: */
0714: public void clearBatch() throws SQLException {
0715: throw new SQLException("Not Supported !");
0716: }
0717:
0718: /**
0719: *Description of the Method
0720: *
0721: * @return Description of the Returned Value
0722: * @exception SQLException Description of Exception
0723: * @since
0724: */
0725: public int[] executeBatch() throws SQLException {
0726: throw new SQLException("Not Supported !");
0727: }
0728:
0729: //---------------------------------------------------------------------
0730: // JDBC 3.0
0731: //---------------------------------------------------------------------
0732:
0733: public boolean getMoreResults(int current) throws SQLException {
0734: throw new UnsupportedOperationException(
0735: "Statement.getMoreResults(int) unsupported");
0736: }
0737:
0738: public ResultSet getGeneratedKeys() throws SQLException {
0739: throw new UnsupportedOperationException(
0740: "Statement.getGeneratedKeys() unsupported");
0741: }
0742:
0743: public int executeUpdate(String sql, int autoGeneratedKeys)
0744: throws SQLException {
0745: throw new UnsupportedOperationException(
0746: "Statement.executeUpdate(String,int) unsupported");
0747: }
0748:
0749: public int executeUpdate(String sql, int[] columnIndexes)
0750: throws SQLException {
0751: throw new UnsupportedOperationException(
0752: "Statement.executeUpdate(String,int[]) unsupported");
0753: }
0754:
0755: public int executeUpdate(String sql, String[] columnNames)
0756: throws SQLException {
0757: throw new UnsupportedOperationException(
0758: "Statement.executeUpdate(String,String[]) unsupported");
0759: }
0760:
0761: public boolean execute(String sql, int autoGeneratedKeys)
0762: throws SQLException {
0763: throw new UnsupportedOperationException(
0764: "Statement.execute(String,int) unsupported");
0765: }
0766:
0767: public boolean execute(String sql, int[] columnIndexes)
0768: throws SQLException {
0769: throw new UnsupportedOperationException(
0770: "Statement.execute(String,int[]) unsupported");
0771: }
0772:
0773: public boolean execute(String sql, String[] columnNames)
0774: throws SQLException {
0775: throw new UnsupportedOperationException(
0776: "Statement.execute(String,String[]) unsupported");
0777: }
0778:
0779: public int getResultSetHoldability() throws SQLException {
0780: throw new UnsupportedOperationException(
0781: "Statement.getResultSetHoldability() unsupported");
0782: }
0783:
0784: public ResultSet executeQuery() throws SQLException {
0785: if (!prepareSql())
0786: throw new SQLException("Error with prepared statement !");
0787: return executeQuery(this .sqlPrepared);
0788:
0789: }
0790:
0791: public int executeUpdate() throws SQLException {
0792: if (!prepareSql())
0793: throw new SQLException("Error with prepared statement !");
0794: executeUpdate(this .sqlPrepared);
0795: return 0;
0796: }
0797:
0798: public void setNull(int parameterIndex, int sqlType)
0799: throws SQLException {
0800: this .setString(parameterIndex, null);
0801: }
0802:
0803: public void setBoolean(int parameterIndex, boolean value)
0804: throws SQLException {
0805: this .setString(parameterIndex, String.valueOf(value));
0806: }
0807:
0808: public void setByte(int parameterIndex, byte value)
0809: throws SQLException {
0810: this .setString(parameterIndex, String.valueOf(value));
0811: }
0812:
0813: public void setShort(int parameterIndex, short value)
0814: throws SQLException {
0815: this .setString(parameterIndex, String.valueOf(value));
0816: }
0817:
0818: public void setInt(int parameterIndex, int value)
0819: throws SQLException {
0820: this .setString(parameterIndex, String.valueOf(value));
0821: }
0822:
0823: public void setLong(int parameterIndex, long value)
0824: throws SQLException {
0825: this .setString(parameterIndex, String.valueOf(value));
0826: }
0827:
0828: public void setFloat(int parameterIndex, float value)
0829: throws SQLException {
0830: this .setString(parameterIndex, String.valueOf(value));
0831: }
0832:
0833: public void setDouble(int parameterIndex, double value)
0834: throws SQLException {
0835: this .setString(parameterIndex, String.valueOf(value));
0836: }
0837:
0838: public void setBigDecimal(int parameterIndex, BigDecimal value)
0839: throws SQLException {
0840: if (value == null) {
0841: this .setString(parameterIndex, value.toString());
0842: } else {
0843: this .setString(parameterIndex, "");
0844: }
0845: }
0846:
0847: public void setDate(int parameterIndex, Date value)
0848: throws SQLException {
0849: if (value == null) {
0850: this .setString(parameterIndex, value.toString());
0851: } else {
0852: this .setString(parameterIndex, "");
0853: }
0854: }
0855:
0856: public void setTime(int parameterIndex, Time value)
0857: throws SQLException {
0858: if (value == null) {
0859: this .setString(parameterIndex, value.toString());
0860: } else {
0861: this .setString(parameterIndex, "");
0862: }
0863: }
0864:
0865: public void setTimestamp(int parameterIndex, Timestamp value)
0866: throws SQLException {
0867: if (value == null) {
0868: this .setString(parameterIndex, value.toString());
0869: } else {
0870: this .setString(parameterIndex, "");
0871: }
0872: }
0873:
0874: public void setAsciiStream(int parameterIndex, InputStream x,
0875: int length) throws SQLException {
0876: /**@todo Implement this java.sql.PreparedStatement method*/
0877: throw new java.lang.UnsupportedOperationException(
0878: "Method setAsciiStream() not yet implemented.");
0879: }
0880:
0881: public void setUnicodeStream(int parameterIndex, InputStream x,
0882: int length) throws SQLException {
0883: /**@todo Implement this java.sql.PreparedStatement method*/
0884: throw new java.lang.UnsupportedOperationException(
0885: "Method setUnicodeStream() not yet implemented.");
0886: }
0887:
0888: public void clearParameters() throws SQLException {
0889: this .sqlPrepared = this .sqlForPrepare;
0890: for (int i = 0; i < parameters.size(); i++)
0891: parameters.set(i, null);
0892: }
0893:
0894: public void setObject(int parameterIndex, Object x,
0895: int targetSqlType, int scale) throws SQLException {
0896: /**@todo Implement this java.sql.PreparedStatement method*/
0897: throw new java.lang.UnsupportedOperationException(
0898: "Method setObject() not yet implemented.");
0899: }
0900:
0901: public void setObject(int parameterIndex, Object x,
0902: int targetSqlType) throws SQLException {
0903: /**@todo Implement this java.sql.PreparedStatement method*/
0904: throw new java.lang.UnsupportedOperationException(
0905: "Method setObject() not yet implemented.");
0906: }
0907:
0908: public void setObject(int parameterIndex, Object x)
0909: throws SQLException {
0910: if (x == null)
0911: setString(parameterIndex, null);
0912: else
0913: setString(parameterIndex, x.toString());
0914: }
0915:
0916: public boolean execute() throws SQLException {
0917: /**@todo Implement this java.sql.PreparedStatement method*/
0918: throw new java.lang.UnsupportedOperationException(
0919: "Method execute() not yet implemented.");
0920: }
0921:
0922: public void addBatch() throws SQLException {
0923: /**@todo Implement this java.sql.PreparedStatement method*/
0924: throw new java.lang.UnsupportedOperationException(
0925: "Method addBatch() not yet implemented.");
0926: }
0927:
0928: public void setCharacterStream(int parameterIndex, Reader reader,
0929: int length) throws SQLException {
0930: /**@todo Implement this java.sql.PreparedStatement method*/
0931: throw new java.lang.UnsupportedOperationException(
0932: "Method setCharacterStream() not yet implemented.");
0933: }
0934:
0935: public void setRef(int i, Ref x) throws SQLException {
0936: /**@todo Implement this java.sql.PreparedStatement method*/
0937: throw new java.lang.UnsupportedOperationException(
0938: "Method setRef() not yet implemented.");
0939: }
0940:
0941: public void setClob(int i, Clob x) throws SQLException {
0942: /**@todo Implement this java.sql.PreparedStatement method*/
0943: throw new java.lang.UnsupportedOperationException(
0944: "Method setClob() not yet implemented.");
0945: }
0946:
0947: public void setArray(int i, Array x) throws SQLException {
0948: /**@todo Implement this java.sql.PreparedStatement method*/
0949: throw new java.lang.UnsupportedOperationException(
0950: "Method setArray() not yet implemented.");
0951: }
0952:
0953: public ResultSetMetaData getMetaData() throws SQLException {
0954: /**@todo Implement this java.sql.PreparedStatement method*/
0955: throw new java.lang.UnsupportedOperationException(
0956: "Method getMetaData() not yet implemented.");
0957: }
0958:
0959: public void setDate(int parameterIndex, Date x, Calendar cal)
0960: throws SQLException {
0961: /**@todo Implement this java.sql.PreparedStatement method*/
0962: throw new java.lang.UnsupportedOperationException(
0963: "Method setDate() not yet implemented.");
0964: }
0965:
0966: public void setTime(int parameterIndex, Time x, Calendar cal)
0967: throws SQLException {
0968: /**@todo Implement this java.sql.PreparedStatement method*/
0969: throw new java.lang.UnsupportedOperationException(
0970: "Method setTime() not yet implemented.");
0971: }
0972:
0973: public void setTimestamp(int parameterIndex, Timestamp x,
0974: Calendar cal) throws SQLException {
0975: /**@todo Implement this java.sql.PreparedStatement method*/
0976: throw new java.lang.UnsupportedOperationException(
0977: "Method setTimestamp() not yet implemented.");
0978: }
0979:
0980: public void setNull(int paramIndex, int sqlType, String typeName)
0981: throws SQLException {
0982: this .setString(paramIndex, null);
0983: }
0984:
0985: public void setURL(int parameterIndex, URL x) throws SQLException {
0986: /**@todo Implement this java.sql.PreparedStatement method*/
0987: throw new java.lang.UnsupportedOperationException(
0988: "Method setURL() not yet implemented.");
0989: }
0990:
0991: public ParameterMetaData getParameterMetaData() throws SQLException {
0992: /**@todo Implement this java.sql.PreparedStatement method*/
0993: throw new java.lang.UnsupportedOperationException(
0994: "Method getParameterMetaData() not yet implemented.");
0995: }
0996:
0997: public void setBinaryStream(int parameterIndex, InputStream value,
0998: int length) throws SQLException {
0999: try {
1000: String hex = Utils.streamToHexString(value);
1001: this .setBytes(parameterIndex, Utils.hexStringToBytes(hex));
1002: } catch (Exception e) {
1003: throw new SQLException("Error in setBinaryStream(): "
1004: + e.getMessage());
1005: }
1006: }
1007:
1008: public void setBlob(int parameterIndex, Blob value)
1009: throws SQLException {
1010: /**@todo Implement this java.sql.PreparedStatement method*/
1011: throw new java.lang.UnsupportedOperationException(
1012: "Method setBlob() not yet implemented.");
1013: }
1014:
1015: public String getSqlStatement() {
1016: return sql;
1017: }
1018:
1019: public void setAsciiStream(int parameterIndex, InputStream x)
1020: throws SQLException {
1021: // TODO Auto-generated method stub
1022: throw new java.lang.UnsupportedOperationException(
1023: "Method setAsciiStream(int,InputStream) not yet implemented.");
1024:
1025: }
1026:
1027: public void setAsciiStream(int parameterIndex, InputStream x,
1028: long length) throws SQLException {
1029: // TODO Auto-generated method stub
1030: throw new java.lang.UnsupportedOperationException(
1031: "Method setAsciiStream(int,InputStream,long) not yet implemented.");
1032:
1033: }
1034:
1035: public void setBinaryStream(int parameterIndex, InputStream x)
1036: throws SQLException {
1037: // TODO Auto-generated method stub
1038: throw new java.lang.UnsupportedOperationException(
1039: "Method setBinaryStream(int,InputStream) not yet implemented.");
1040:
1041: }
1042:
1043: public void setBinaryStream(int parameterIndex, InputStream x,
1044: long length) throws SQLException {
1045: // TODO Auto-generated method stub
1046: throw new java.lang.UnsupportedOperationException(
1047: "Method setBinaryStream(int,InputStream,long) not yet implemented.");
1048:
1049: }
1050:
1051: public void setBlob(int parameterIndex, InputStream inputStream)
1052: throws SQLException {
1053: // TODO Auto-generated method stub
1054: throw new java.lang.UnsupportedOperationException(
1055: "Method setBlob(int,InputStream) not yet implemented.");
1056:
1057: }
1058:
1059: public void setBlob(int parameterIndex, InputStream inputStream,
1060: long length) throws SQLException {
1061: // TODO Auto-generated method stub
1062: throw new java.lang.UnsupportedOperationException(
1063: "Method setBlob(int,InputStream,long) not yet implemented.");
1064:
1065: }
1066:
1067: public void setCharacterStream(int parameterIndex, Reader reader)
1068: throws SQLException {
1069: // TODO Auto-generated method stub
1070: throw new java.lang.UnsupportedOperationException(
1071: "Method setCharacterStream(int,Reader) not yet implemented.");
1072:
1073: }
1074:
1075: public void setCharacterStream(int parameterIndex, Reader reader,
1076: long length) throws SQLException {
1077: // TODO Auto-generated method stub
1078: throw new java.lang.UnsupportedOperationException(
1079: "Method setCharacterStream(int,Reader,long) not yet implemented.");
1080:
1081: }
1082:
1083: public void setClob(int parameterIndex, Reader reader)
1084: throws SQLException {
1085: // TODO Auto-generated method stub
1086: throw new java.lang.UnsupportedOperationException(
1087: "Method setClob(int,Reader) not yet implemented.");
1088:
1089: }
1090:
1091: public void setClob(int parameterIndex, Reader reader, long length)
1092: throws SQLException {
1093: // TODO Auto-generated method stub
1094: throw new java.lang.UnsupportedOperationException(
1095: "Method setClob(int,Reader,long) not yet implemented.");
1096:
1097: }
1098:
1099: public void setNCharacterStream(int parameterIndex, Reader value)
1100: throws SQLException {
1101: // TODO Auto-generated method stub
1102: throw new java.lang.UnsupportedOperationException(
1103: "Method setNCharacterStream(int,Reader) not yet implemented.");
1104:
1105: }
1106:
1107: public void setNCharacterStream(int parameterIndex, Reader value,
1108: long length) throws SQLException {
1109: // TODO Auto-generated method stub
1110: throw new java.lang.UnsupportedOperationException(
1111: "Method setNCharacterStream(int,Reader,long) not yet implemented.");
1112:
1113: }
1114:
1115: public void setNClob(int parameterIndex, NClob value)
1116: throws SQLException {
1117: // TODO Auto-generated method stub
1118: throw new java.lang.UnsupportedOperationException(
1119: "Method setNClob(int,NClob) not yet implemented.");
1120:
1121: }
1122:
1123: public void setNClob(int parameterIndex, Reader reader)
1124: throws SQLException {
1125: // TODO Auto-generated method stub
1126: throw new java.lang.UnsupportedOperationException(
1127: "Method setNClob(int,Reader) not yet implemented.");
1128:
1129: }
1130:
1131: public void setNClob(int parameterIndex, Reader reader, long length)
1132: throws SQLException {
1133: // TODO Auto-generated method stub
1134: throw new java.lang.UnsupportedOperationException(
1135: "Method setNClob(int,Reader,long) not yet implemented.");
1136:
1137: }
1138:
1139: public void setNString(int parameterIndex, String value)
1140: throws SQLException {
1141: // TODO Auto-generated method stub
1142: throw new java.lang.UnsupportedOperationException(
1143: "Method setNString(int,String) not yet implemented.");
1144:
1145: }
1146:
1147: public void setRowId(int parameterIndex, RowId x)
1148: throws SQLException {
1149: // TODO Auto-generated method stub
1150: throw new java.lang.UnsupportedOperationException(
1151: "Method setRowId(int,RowId) not yet implemented.");
1152:
1153: }
1154:
1155: public void setSQLXML(int parameterIndex, SQLXML xmlObject)
1156: throws SQLException {
1157: // TODO Auto-generated method stub
1158: throw new java.lang.UnsupportedOperationException(
1159: "Method setSQLXML(int,SQLXML) not yet implemented.");
1160:
1161: }
1162:
1163: public boolean isClosed() throws SQLException {
1164: // TODO Auto-generated method stub
1165: return false;
1166: }
1167:
1168: public boolean isPoolable() throws SQLException {
1169: // TODO Auto-generated method stub
1170: return false;
1171: }
1172:
1173: public void setPoolable(boolean poolable) throws SQLException {
1174: // TODO Auto-generated method stub
1175: throw new java.lang.UnsupportedOperationException(
1176: "Method setPoolable(boolean) not yet implemented.");
1177:
1178: }
1179:
1180: public boolean isWrapperFor(Class<?> iface) throws SQLException {
1181: // TODO Auto-generated method stub
1182: return false;
1183: }
1184:
1185: public <T> T unwrap(Class<T> iface) throws SQLException {
1186: // TODO Auto-generated method stub
1187: return null;
1188: }
1189:
1190: }
|