2
Copyright (C) 2009 Volker Berlin (i-net software)
4
This software is provided 'as-is', without any express or implied
5
warranty. In no event will the authors be held liable for any damages
6
arising from the use of this software.
8
Permission is granted to anyone to use this software for any purpose,
9
including commercial applications, and to alter it and redistribute it
10
freely, subject to the following restrictions:
12
1. The origin of this software must not be misrepresented; you must not
13
claim that you wrote the original software. If you use this software
14
in a product, an acknowledgment in the product documentation would be
15
appreciated but is not required.
16
2. Altered source versions must be plainly marked as such, and must not be
17
misrepresented as being the original software.
18
3. This notice may not be removed or altered from any source distribution.
24
package sun.jdbc.odbc;
26
import java.io.InputStream;
27
import java.io.Reader;
28
import java.math.BigDecimal;
30
import java.sql.Array;
34
import java.sql.NClob;
35
import java.sql.ParameterMetaData;
36
import java.sql.PreparedStatement;
38
import java.sql.ResultSet;
39
import java.sql.ResultSetMetaData;
40
import java.sql.RowId;
41
import java.sql.SQLException;
42
import java.sql.SQLXML;
44
import java.sql.Timestamp;
45
import java.sql.Types;
46
import java.util.Calendar;
48
import cli.System.Data.*;
49
import cli.System.Data.Common.*;
50
import cli.System.Data.Odbc.*;
53
* @author Volker Berlin
55
public class JdbcOdbcPreparedStatement extends JdbcOdbcStatement implements PreparedStatement{
57
public JdbcOdbcPreparedStatement(JdbcOdbcConnection jdbcConn, OdbcCommand command, String sql, int resultSetType, int resultSetConcurrency){
58
super(jdbcConn, command, resultSetType, resultSetConcurrency);
59
command.set_CommandText(sql);
64
public void addBatch() throws SQLException{
65
// TODO Auto-generated method stub
70
public void clearParameters(){
71
DbParameterCollection params = command.get_Parameters();
76
public boolean execute() throws SQLException{
77
return super.execute(null);
81
public ResultSet executeQuery() throws SQLException{
82
return super.executeQuery(null);
86
public int executeUpdate() throws SQLException{
87
return super.executeUpdate(null);
91
public ResultSetMetaData getMetaData() throws SQLException{
92
ResultSet rs = getResultSet();
96
DbDataReader reader = command.ExecuteReader(CommandBehavior.wrap(CommandBehavior.SchemaOnly));
97
JdbcOdbcResultSetMetaData metadata = new JdbcOdbcResultSetMetaData(reader);
103
public ParameterMetaData getParameterMetaData(){
104
throw new UnsupportedOperationException();
108
public void setArray(int parameterIndex, Array x) throws SQLException{
109
setObject(parameterIndex, x, Types.ARRAY);
113
public void setAsciiStream(int parameterIndex, InputStream x) throws SQLException{
114
setObject(parameterIndex, x, Types.LONGVARCHAR);
118
public void setAsciiStream(int parameterIndex, InputStream x, int length) throws SQLException{
119
setObject(parameterIndex, x, Types.LONGVARCHAR, length);
123
public void setAsciiStream(int parameterIndex, InputStream x, long length) throws SQLException{
124
setObject(parameterIndex, x, Types.LONGVARCHAR, (int)length);
128
public void setBigDecimal(int parameterIndex, BigDecimal x) throws SQLException{
129
setObject(parameterIndex, x, Types.DECIMAL);
133
public void setBinaryStream(int parameterIndex, InputStream x) throws SQLException{
134
setObject(parameterIndex, x, Types.LONGVARBINARY);
138
public void setBinaryStream(int parameterIndex, InputStream x, int length) throws SQLException{
139
setObject(parameterIndex, x, Types.LONGVARBINARY, length);
143
public void setBinaryStream(int parameterIndex, InputStream x, long length) throws SQLException{
144
setObject(parameterIndex, x, Types.LONGVARBINARY, (int)length);
148
public void setBlob(int parameterIndex, Blob x) throws SQLException{
149
setObject(parameterIndex, x, Types.BLOB);
153
public void setBlob(int parameterIndex, InputStream x) throws SQLException{
154
setObject(parameterIndex, x, Types.BLOB);
158
public void setBlob(int parameterIndex, InputStream x, long length) throws SQLException{
159
setObject(parameterIndex, x, Types.BLOB, (int)length);
163
public void setBoolean(int parameterIndex, boolean x) throws SQLException{
164
setObject(parameterIndex, Boolean.valueOf(x), Types.BOOLEAN);
168
public void setByte(int parameterIndex, byte x) throws SQLException{
169
setObject(parameterIndex, Byte.valueOf(x), Types.TINYINT);
173
public void setBytes(int parameterIndex, byte[] x) throws SQLException{
174
setObject(parameterIndex, x, Types.BINARY);
178
public void setCharacterStream(int parameterIndex, Reader x) throws SQLException{
179
setObject(parameterIndex, x, Types.LONGVARCHAR);
183
public void setCharacterStream(int parameterIndex, Reader x, int length) throws SQLException{
184
setObject(parameterIndex, x, Types.NCLOB, length);
188
public void setCharacterStream(int parameterIndex, Reader x, long length) throws SQLException{
189
setObject(parameterIndex, x, Types.LONGVARCHAR, (int)length);
193
public void setClob(int parameterIndex, Clob x) throws SQLException{
194
setObject(parameterIndex, x, Types.CLOB);
198
public void setClob(int parameterIndex, Reader x) throws SQLException{
199
setObject(parameterIndex, x, Types.CLOB);
203
public void setClob(int parameterIndex, Reader x, long length) throws SQLException{
204
setObject(parameterIndex, x, Types.CLOB, (int)length);
208
public void setDate(int parameterIndex, Date x) throws SQLException{
209
setObject(parameterIndex, x, Types.DATE);
213
public void setDate(int parameterIndex, Date x, Calendar cal) throws SQLException{
214
JdbcOdbcUtils.convertCalendarToLocalDate(x, cal);
215
setObject(parameterIndex, x, Types.DATE);
219
public void setDouble(int parameterIndex, double x) throws SQLException{
220
setObject(parameterIndex, Double.valueOf(x), Types.DOUBLE);
224
public void setFloat(int parameterIndex, float x) throws SQLException{
225
setObject(parameterIndex, Float.valueOf(x), Types.FLOAT);
229
public void setInt(int parameterIndex, int x) throws SQLException{
230
setObject(parameterIndex, Integer.valueOf(x), Types.INTEGER);
234
public void setLong(int parameterIndex, long x) throws SQLException{
235
setObject(parameterIndex, Long.valueOf(x), Types.BIGINT);
239
public void setNCharacterStream(int parameterIndex, Reader x) throws SQLException{
240
setObject(parameterIndex, x, Types.LONGNVARCHAR);
244
public void setNCharacterStream(int parameterIndex, Reader x, long length) throws SQLException{
245
setObject(parameterIndex, x, Types.LONGNVARCHAR, (int)length);
249
public void setNClob(int parameterIndex, NClob x) throws SQLException{
250
setObject(parameterIndex, x, Types.NCLOB);
254
public void setNClob(int parameterIndex, Reader x) throws SQLException{
255
setObject(parameterIndex, x, Types.NCLOB);
259
public void setNClob(int parameterIndex, Reader x, long length) throws SQLException{
260
setObject(parameterIndex, x, Types.NCLOB, (int)length);
264
public void setNString(int parameterIndex, String x) throws SQLException{
265
setObject(parameterIndex, x, Types.NVARCHAR);
269
public void setNull(int parameterIndex, int sqlType) throws SQLException{
270
setObject(parameterIndex, null, sqlType);
274
public void setNull(int parameterIndex, int sqlType, String typeName) throws SQLException{
275
setObject(parameterIndex, null, sqlType);
279
public void setObject(int parameterIndex, Object x) throws SQLException{
280
setObject(parameterIndex, x, Types.OTHER, -1);
284
public void setObject(int parameterIndex, Object x, int targetSqlType) throws SQLException{
285
setObject(parameterIndex, x, targetSqlType, -1);
289
public void setObject(int parameterIndex, Object x, int targetSqlType, int scaleOrLength) throws SQLException{
290
DbParameter para = getPara(parameterIndex);
291
para.set_Value(JdbcOdbcUtils.convertJava2Net(x, scaleOrLength));
292
if(para.get_Direction().Value == ParameterDirection.Output){
293
para.set_Direction(ParameterDirection.wrap(ParameterDirection.InputOutput));
296
if(targetSqlType != Types.OTHER){
297
para.set_DbType(DbType.wrap(JdbcOdbcUtils.convertJdbc2AdoNetType(targetSqlType)));
300
if(scaleOrLength >= 0){
301
switch(targetSqlType){
304
para.set_Scale((byte)scaleOrLength);
310
public void setRef(int parameterIndex, Ref x) throws SQLException{
311
setObject(parameterIndex, x, Types.REF);
315
public void setRowId(int parameterIndex, RowId x) throws SQLException{
316
setObject(parameterIndex, x, Types.ROWID);
320
public void setSQLXML(int parameterIndex, SQLXML x) throws SQLException{
321
setObject(parameterIndex, x, Types.SQLXML);
325
public void setShort(int parameterIndex, short x) throws SQLException{
326
setObject(parameterIndex, Short.valueOf(x), Types.SMALLINT);
330
public void setString(int parameterIndex, String x) throws SQLException{
331
setObject(parameterIndex, x, Types.VARCHAR);
335
public void setTime(int parameterIndex, Time x) throws SQLException{
336
setObject(parameterIndex, x, Types.TIME);
340
public void setTime(int parameterIndex, Time x, Calendar cal) throws SQLException{
341
JdbcOdbcUtils.convertCalendarToLocalDate(x, cal);
342
setObject(parameterIndex, x, Types.TIME);
346
public void setTimestamp(int parameterIndex, Timestamp x) throws SQLException{
347
setObject(parameterIndex, x, Types.TIMESTAMP);
351
public void setTimestamp(int parameterIndex, Timestamp x, Calendar cal) throws SQLException{
352
JdbcOdbcUtils.convertCalendarToLocalDate(x, cal);
353
setObject(parameterIndex, x, Types.TIMESTAMP);
357
public void setURL(int parameterIndex, URL x) throws SQLException{
358
setObject(parameterIndex, x, Types.DATALINK);
362
public void setUnicodeStream(int parameterIndex, InputStream x, int length) throws SQLException{
363
setObject(parameterIndex, x, Types.LONGNVARCHAR, length);
368
* Get the DbParameter from the current command. If the parameter does not exits in the collection then add it.
370
* @param parameterIndex
371
* The JDBC parameter index starting with 1
372
* @return the DbParameter for the index.
373
* @throws SQLException
374
* If any error occur.
376
protected DbParameter getPara(int parameterIndex) throws SQLException{
378
DbParameterCollection params = command.get_Parameters();
379
while(params.get_Count() < parameterIndex){
380
params.Add(command.CreateParameter());
382
return params.get_Item(parameterIndex - 1);
383
}catch(Throwable th){
384
throw JdbcOdbcUtils.createSQLException(th);