*** empty log message ***
[csql.git] / src / jdbc / JdbcSqlPreparedStatement.java
blob9af1131ab8ae045e60b5f2cb1005e1097463b2bf
1 package csql.jdbc;
2 import java.io.InputStream;
3 import java.io.Reader;
4 import java.math.BigDecimal;
5 import java.util.Calendar;
6 import java.net.URL;
8 import java.sql.Connection;
9 import java.sql.Statement;
10 import java.sql.PreparedStatement;
11 import java.sql.ResultSet;
12 import java.sql.Blob;
13 import java.sql.Clob;
14 import java.sql.ResultSetMetaData;
15 import java.sql.ParameterMetaData;
16 import java.sql.SQLException;
17 import java.sql.Ref;
18 import java.sql.Array;
19 import java.sql.SQLXML;
20 import java.sql.RowId;
22 import java.sql.NClob;
23 public class JdbcSqlPreparedStatement extends JdbcSqlStatement
24 implements PreparedStatement
26 public JdbcSqlParameterMetaData pmtd;
27 JdbcSqlPreparedStatement(Connection con)
29 super(con);
31 public void clearParameters() throws SQLException
33 //TODO
34 return;
36 public boolean execute() throws SQLException
38 return executeInt();
40 public ResultSet executeQuery() throws SQLException
42 if(!executeInt())
43 throw getException(CSQL_NOT_QUERY);
44 //Praba changed this
45 rs.setStmt( this );
46 if( isFirstExecute) {
47 rs.setProjField();
48 isFirstExecute = false;
50 return( rs );
51 //return null;
53 public int executeUpdate() throws SQLException
55 if(executeInt())
56 throw getException(CSQL_NOT_UPDATE);
57 return(rowsAffect);
59 public ResultSetMetaData getMetaData() throws SQLException
61 //TODO
62 return null;
65 public ParameterMetaData getParameterMetaData() throws SQLException
67 pmtd = new JdbcSqlParameterMetaData();
68 pmtd.setStmt(this);
69 return pmtd;
71 public void setByte(int param, byte value) throws SQLException
73 jniStmt.setByte(param, value);
74 return;
76 public void setDate(int param, java.sql.Date value) throws SQLException
78 jniStmt.setDate(param, value);
79 return;
81 public void setDouble(int param, double value) throws SQLException
83 jniStmt.setDouble(param, value);
84 return;
86 public void setFloat(int param, float value) throws SQLException
88 jniStmt.setFloat(param, value);
89 return;
91 public void setInt(int param, int value) throws SQLException
93 jniStmt.setInt(param, value);
94 return;
96 public void setLong(int param, long value) throws SQLException
98 jniStmt.setLong(param, value);
99 return;
101 public void setNull (int param, int sqlType) throws SQLException
103 jniStmt.setNull(param);
104 return;
106 public void setObject(int param, Object obj) throws SQLException
108 if(obj instanceof Double)
109 setDouble(param, ((Double)obj).doubleValue() );
110 else if(obj instanceof Float)
111 setFloat(param, ((Float)obj).floatValue() );
112 else if(obj instanceof Long)
113 setLong(param, ((Long)obj).longValue() );
114 else if(obj instanceof Integer)
115 setInt(param, ((Integer)obj).intValue() );
116 else if(obj instanceof Short)
117 setShort(param, ((Short)obj).shortValue() );
118 else if(obj instanceof Byte)
119 setByte(param, ((Byte)obj).byteValue() );
120 else if(obj instanceof java.sql.Date )
121 setDate(param, ((java.sql.Date) obj));
122 else if(obj instanceof java.sql.Time )
123 setTime(param, ((java.sql.Time) obj));
124 else if(obj instanceof java.sql.Timestamp )
125 setTimestamp(param, ((java.sql.Timestamp) obj));
126 else if(obj instanceof String )
127 setString(param, ((String) obj));
128 else
129 throw getException(CSQL_INVALID_DATATYPE);
131 return;
133 public void setShort(int param, short value) throws SQLException
135 jniStmt.setShort(param, value);
136 return;
138 public void setString(int param, String value) throws SQLException
140 jniStmt.setString(param, value);
141 return;
143 public void setTime(int param, java.sql.Time value) throws SQLException
145 jniStmt.setTime(param, value);
146 return;
148 public void setTimestamp(int param, java.sql.Timestamp value) throws SQLException
150 jniStmt.setTimestamp(param, value);
151 return;
157 //Unsupported APIs
158 public void addBatch() throws SQLException
160 if (JSqlError.isDebug) System.out.println("JdbcSqlPreparedStatement::addBatch called");
161 throw getException(CSQL_NOT_SUPPORTED);
163 public void setArray (int i, Array value) throws SQLException
165 if (JSqlError.isDebug) System.out.println("JdbcSqlPreparedStatement::setArray called");
166 throw getException(CSQL_NOT_SUPPORTED);
168 public void setAsciiStream(int parameterIndex, InputStream value, int length)
169 throws SQLException
171 if (JSqlError.isDebug) System.out.println("JdbcSqlPreparedStatement::setAsciiStream called");
172 throw getException(CSQL_NOT_SUPPORTED);
174 public void setBigDecimal(int parameterIndex, BigDecimal value) throws SQLException
176 if (JSqlError.isDebug) System.out.println("JdbcSqlPreparedStatement::setBigDecimal called");
177 throw getException(CSQL_NOT_SUPPORTED);
179 public void setBinaryStream(int parameterIndex, InputStream value, int length)
180 throws SQLException
182 if (JSqlError.isDebug) System.out.println("JdbcSqlPreparedStatement::setBinaryStream called");
183 throw getException(CSQL_NOT_SUPPORTED);
185 public void setBlob(int i, Blob value) throws SQLException
187 if (JSqlError.isDebug) System.out.println("JdbcSqlPreparedStatement::setBlob called");
188 throw getException(CSQL_NOT_SUPPORTED);
190 public void setBoolean (int param, boolean value) throws SQLException
192 if (JSqlError.isDebug) System.out.println("JdbcSqlPreparedStatement::setBoolean called");
193 throw getException(CSQL_NOT_SUPPORTED);
195 public void setBytes(int param, byte value[]) throws SQLException
197 if (JSqlError.isDebug) System.out.println("JdbcSqlPreparedStatement::setBytes called");
198 throw getException(CSQL_NOT_SUPPORTED);
200 public void setCharacterStream(int param, Reader reader, int length)
201 throws SQLException
203 if (JSqlError.isDebug) System.out.println("JdbcSqlPreparedStatement::setCharacterStream called");
204 throw getException(CSQL_NOT_SUPPORTED);
206 public void setClob (int i, Clob value) throws SQLException
208 if (JSqlError.isDebug) System.out.println("JdbcSqlPreparedStatement::setClob called");
209 throw getException(CSQL_NOT_SUPPORTED);
211 public void setDate(int param, java.sql.Date value, Calendar cal)
212 throws SQLException
214 if (JSqlError.isDebug) System.out.println("JdbcSqlPreparedStatement::setDate called");
215 throw getException(CSQL_NOT_SUPPORTED);
217 public void setNull (int param, int sqlType, String typeName)
218 throws SQLException
220 if (JSqlError.isDebug) System.out.println("JdbcSqlPreparedStatement::setNull called");
221 throw getException(CSQL_NOT_SUPPORTED);
223 public void setObject (int param, Object value, int targetSqlType)
224 throws SQLException
226 if (JSqlError.isDebug) System.out.println("JdbcSqlPreparedStatement::setObject(int, Object, int) called");
227 throw getException(CSQL_NOT_SUPPORTED);
229 public void setObject (int param, Object value, int targetSqlType, int scale) throws SQLException
231 if (JSqlError.isDebug) System.out.println("JdbcSqlPreparedStatement::setObject(int, Object, int, int) called");
232 throw getException(CSQL_NOT_SUPPORTED);
234 public void setRef(int i, Ref value) throws SQLException
236 if (JSqlError.isDebug) System.out.println("JdbcSqlPreparedStatement::setRef called");
237 throw getException(CSQL_NOT_SUPPORTED);
239 public void setTime(int param, java.sql.Time value, Calendar cal)
240 throws SQLException
242 if (JSqlError.isDebug) System.out.println("JdbcSqlPreparedStatement::setTime called");
243 throw getException(CSQL_NOT_SUPPORTED);
245 public void setTimestamp(int param, java.sql.Timestamp value,
246 Calendar cal) throws SQLException
248 if (JSqlError.isDebug) System.out.println("JdbcSqlPreparedStatement::setTimeStamp called");
249 throw getException(CSQL_NOT_SUPPORTED);
251 public void setUnicodeStream (int param, InputStream value, int length)
252 throws SQLException
254 if (JSqlError.isDebug) System.out.println("JdbcSqlPreparedStatement::setUnicodeStream called");
255 throw getException(CSQL_NOT_SUPPORTED);
257 public void setURL(int parameterName, URL value) throws SQLException
259 if (JSqlError.isDebug) System.out.println("JdbcSqlPreparedStatement::setURL called");
260 throw getException(CSQL_NOT_SUPPORTED);
262 //java 1.6 methods
263 public void setBlob(int paramIndex, InputStream value ) throws SQLException
265 if (JSqlError.isDebug) System.out.println("JdbcSqlPreparedStatement::setBlob(int, InputStream) called");
266 throw getException(CSQL_NOT_SUPPORTED);
268 public void setBlob(int paramIndex, InputStream value, long length ) throws SQLException
270 if (JSqlError.isDebug) System.out.println("JdbcSqlPreparedStatement::setBlob(int, InputStream, long) called");
271 throw getException(CSQL_NOT_SUPPORTED);
273 public void setClob(int paramIndex, Reader value ) throws SQLException
275 if (JSqlError.isDebug) System.out.println("JdbcSqlPreparedStatement::setClob(int, Reader) called");
276 throw getException(CSQL_NOT_SUPPORTED);
278 public void setClob(int paramIndex, Reader value, long length ) throws SQLException
280 if (JSqlError.isDebug) System.out.println("JdbcSqlPreparedStatement::setClob(int, Reader, long) called");
281 throw getException(CSQL_NOT_SUPPORTED);
283 public void setNCharacterStream(int paramIndex, Reader value)
284 throws SQLException
286 if (JSqlError.isDebug) System.out.println("JdbcSqlPreparedStatement::setNCharacterStream(int, Reader) called");
287 throw getException(CSQL_NOT_SUPPORTED);
289 public void setNCharacterStream(int paramIndex,Reader value,long length)
290 throws SQLException
292 if (JSqlError.isDebug) System.out.println("JdbcSqlPreparedStatement::setNCharacterStream(int, Reader, long) called");
293 throw getException(CSQL_NOT_SUPPORTED);
295 public void setNClob(int paramIndex, NClob value)
296 throws SQLException
298 if (JSqlError.isDebug) System.out.println("JdbcSqlPreparedStatement::setNClob(int, NClob) called");
299 throw getException(CSQL_NOT_SUPPORTED);
301 public void setNClob(int paramIndex, Reader value)
302 throws SQLException
304 if (JSqlError.isDebug) System.out.println("JdbcSqlPreparedStatement::setNClob(int, Reader) called");
305 throw getException(CSQL_NOT_SUPPORTED);
307 public void setNClob(int paramIndex, Reader value, long length)
308 throws SQLException
310 if (JSqlError.isDebug) System.out.println("JdbcSqlPreparedStatement::setNClob(int, Reader, long) called");
311 throw getException(CSQL_NOT_SUPPORTED);
313 public void setNString(int paramIndex, String value)
314 throws SQLException
316 if (JSqlError.isDebug) System.out.println("JdbcSqlPreparedStatement::setNString called");
317 throw getException(CSQL_NOT_SUPPORTED);
319 public void setCharacterStream(int param, Reader reader)
320 throws SQLException
322 if (JSqlError.isDebug) System.out.println("JdbcSqlPreparedStatement::setCharacterStream(int, Reader) called");
323 throw getException(CSQL_NOT_SUPPORTED);
325 public void setCharacterStream(int param, Reader reader, long length)
326 throws SQLException
328 if (JSqlError.isDebug) System.out.println("JdbcSqlPreparedStatement::setCharacterStream(int, Reader, long) called");
329 throw getException(CSQL_NOT_SUPPORTED);
331 public void setBinaryStream(int parameterIndex, InputStream value)
332 throws SQLException
334 if (JSqlError.isDebug) System.out.println("JdbcSqlPreparedStatement::setBinaryStream(int, InputStream) called");
335 throw getException(CSQL_NOT_SUPPORTED);
337 public void setBinaryStream(int parameterIndex, InputStream value, long length)
338 throws SQLException
340 if (JSqlError.isDebug) System.out.println("JdbcSqlPreparedStatement::setBinaryStream(int, InputStream, long) called");
341 throw getException(CSQL_NOT_SUPPORTED);
343 public void setAsciiStream(int parameterIndex, InputStream value)
344 throws SQLException
346 if (JSqlError.isDebug) System.out.println("JdbcSqlPreparedStatement::setAsciiStream(int, InputStream) called");
347 throw getException(CSQL_NOT_SUPPORTED);
349 public void setAsciiStream(int parameterIndex, InputStream value, long length)
350 throws SQLException
352 if (JSqlError.isDebug) System.out.println("JdbcSqlPreparedStatement::setAsciiStream(int, InputStream, long) called");
353 throw getException(CSQL_NOT_SUPPORTED);
355 public void setSQLXML(int paramIndex, SQLXML xmlObj) throws SQLException
357 if (JSqlError.isDebug) System.out.println("JdbcSqlPreparedStatement::setSQLXML called");
358 throw getException(CSQL_NOT_SUPPORTED);
360 public void setRowId(int paramIndex, RowId x) throws SQLException
362 if (JSqlError.isDebug) System.out.println("JdbcSqlPreparedStatement::setRowId called");
363 throw getException(CSQL_NOT_SUPPORTED);