01: package com.mysql.jdbc;
02:
03: import java.io.Reader;
04: import java.sql.NClob;
05: import java.sql.RowId;
06: import java.sql.SQLException;
07: import java.sql.SQLXML;
08: import java.sql.Types;
09:
10: import com.mysql.jdbc.PreparedStatement;
11: import com.mysql.jdbc.exceptions.NotYetImplementedException;
12:
13: public class JDBC4PreparedStatementHelper {
14: private JDBC4PreparedStatementHelper() {
15:
16: }
17:
18: static void setRowId(PreparedStatement pstmt, int parameterIndex,
19: RowId x) throws SQLException {
20: throw new NotYetImplementedException();
21: }
22:
23: /**
24: * JDBC 4.0 Set a NCLOB parameter.
25: *
26: * @param i
27: * the first parameter is 1, the second is 2, ...
28: * @param x
29: * an object representing a NCLOB
30: *
31: * @throws SQLException
32: * if a database error occurs
33: */
34: static void setNClob(PreparedStatement pstmt, int parameterIndex,
35: NClob value) throws SQLException {
36: if (value == null) {
37: pstmt.setNull(parameterIndex, java.sql.Types.NCLOB);
38: } else {
39: pstmt.setNCharacterStream(parameterIndex, value
40: .getCharacterStream(), value.length());
41: }
42: }
43:
44: static void setNClob(PreparedStatement pstmt, int parameterIndex,
45: Reader reader) throws SQLException {
46: pstmt.setNCharacterStream(parameterIndex, reader);
47: }
48:
49: /**
50: * JDBC 4.0 Set a NCLOB parameter.
51: *
52: * @param parameterIndex
53: * the first parameter is 1, the second is 2, ...
54: * @param reader
55: * the java reader which contains the UNICODE data
56: * @param length
57: * the number of characters in the stream
58: *
59: * @throws SQLException
60: * if a database error occurs
61: */
62: static void setNClob(PreparedStatement pstmt, int parameterIndex,
63: Reader reader, long length) throws SQLException {
64: if (reader == null) {
65: pstmt.setNull(parameterIndex, java.sql.Types.NCLOB);
66: } else {
67: pstmt.setNCharacterStream(parameterIndex, reader, length);
68: }
69: }
70:
71: static void setSQLXML(PreparedStatement pstmt, int parameterIndex,
72: SQLXML xmlObject) throws SQLException {
73: if (xmlObject == null) {
74: pstmt.setNull(parameterIndex, Types.SQLXML);
75: } else {
76: // FIXME: Won't work for Non-MYSQL SQLXMLs
77: pstmt.setCharacterStream(parameterIndex,
78: ((JDBC4MysqlSQLXML) xmlObject)
79: .serializeAsCharacterStream());
80: }
81: }
82: }
|