diff --git a/jaydebeapi/__init__.py b/jaydebeapi/__init__.py index a890c3d..5167920 100644 --- a/jaydebeapi/__init__.py +++ b/jaydebeapi/__init__.py @@ -617,10 +617,18 @@ def _unknownSqlTypeConverter(rs, col): return rs.getObject(col) def _to_datetime(rs, col): - java_val = rs.getTimestamp(col) + import jpype + SQLException = jpype.java.sql.SQLException + try: + java_val = rs.getTimestamp(col) + except: + java_val = bytes(rs.getBytes(col)).decode('utf-8') if not java_val: return - d = datetime.datetime.strptime(str(java_val)[:19], "%Y-%m-%d %H:%M:%S") + try: + d = datetime.datetime.strptime(str(java_val)[:19], "%Y-%m-%d %H:%M:%S") + except ValueError: + return "" d = d.replace(microsecond=int(str(java_val.getNanos())[:6])) return str(d)