KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > ziclix > python > sql > JDBC30DataHandler


1 /*
2  * Jython Database Specification API 2.0
3  *
4  * $Id: JDBC30DataHandler.java,v 1.1 2003/07/03 20:06:04 bzimmer Exp $
5  *
6  * Copyright (c) 2002 brian zimmer <bzimmer@ziclix.com>
7  *
8  */

9 package com.ziclix.python.sql;
10
11 import org.python.core.PyObject;
12
13 import java.sql.PreparedStatement JavaDoc;
14 import java.sql.SQLException JavaDoc;
15 import java.sql.ParameterMetaData JavaDoc;
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: 1.1 $
23  */

24 public class JDBC30DataHandler extends FilterDataHandler {
25
26   static {
27     try {
28       Class.forName("java.sql.ParameterMetaData");
29     } catch (ClassNotFoundException JavaDoc e) {
30       throw new RuntimeException JavaDoc("JDBC3.0 required to use this DataHandler");
31     }
32   }
33
34   /**
35    * Handle JDBC 3.0 additions.
36    *
37    */

38   public JDBC30DataHandler(DataHandler datahandler) {
39       super(datahandler);
40   }
41
42   /**
43    * Use ParameterMetaData if available to dynamically cast to the appropriate
44    * JDBC type.
45    *
46    * @param stmt the prepared statement
47    * @param index the index currently being used
48    * @param object the object to be set on the statement
49    * @throws SQLException
50    */

51   public void setJDBCObject(PreparedStatement JavaDoc stmt, int index, PyObject object) throws SQLException JavaDoc {
52     ParameterMetaData JavaDoc meta = stmt.getParameterMetaData();
53     super.setJDBCObject(stmt, index, object, meta.getParameterType(index));
54   }
55 }
56
57
Popular Tags