01: /*
02: * Jython Database Specification API 2.0
03: *
04: * $Id: JDBC30DataHandler.java 2315 2003-07-03 20:06:04Z bzimmer $
05: *
06: * Copyright (c) 2002 brian zimmer <bzimmer@ziclix.com>
07: *
08: */
09: package com.ziclix.python.sql;
10:
11: import org.python.core.PyObject;
12:
13: import java.sql.PreparedStatement;
14: import java.sql.SQLException;
15: import java.sql.ParameterMetaData;
16:
17: /**
18: * Support for JDBC 3.x additions, notably ParameterMetaData.
19: *
20: * @author brian zimmer
21: * @author last revised by $Author: bzimmer $
22: * @version $Revision: 2315 $
23: */
24: public class JDBC30DataHandler extends FilterDataHandler {
25:
26: static {
27: try {
28: Class.forName("java.sql.ParameterMetaData");
29: } catch (ClassNotFoundException e) {
30: throw new RuntimeException(
31: "JDBC3.0 required to use this DataHandler");
32: }
33: }
34:
35: /**
36: * Handle JDBC 3.0 additions.
37: *
38: */
39: public JDBC30DataHandler(DataHandler datahandler) {
40: super (datahandler);
41: }
42:
43: /**
44: * Use ParameterMetaData if available to dynamically cast to the appropriate
45: * JDBC type.
46: *
47: * @param stmt the prepared statement
48: * @param index the index currently being used
49: * @param object the object to be set on the statement
50: * @throws SQLException
51: */
52: public void setJDBCObject(PreparedStatement stmt, int index,
53: PyObject object) throws SQLException {
54: ParameterMetaData meta = stmt.getParameterMetaData();
55: super.setJDBCObject(stmt, index, object, meta
56: .getParameterType(index));
57: }
58: }
|