Permalink
Browse files

Error reporting from JDBCUtils.java to C code improved,comments added…

… in JDBCUtils.java,README formatting corrected
  • Loading branch information...
1 parent d174c44 commit 7b985413e050f8bcd654cc2d065b169854cdbdcf @atris committed Aug 13, 2012
Showing with 255 additions and 104 deletions.
  1. +49 −11 JDBCUtils.java
  2. +138 −44 README
  3. +68 −49 jdbc_fdw.c
View
@@ -30,6 +30,8 @@
private Statement sql;
private String[] Iterate;
private static JDBCDriverLoader JDBC_Driver_Loader;
+ private StringWriter exception_stack_trace_string_writer;
+ private PrintWriter exception_stack_trace_print_writer;
/*
* Initialize
@@ -50,19 +52,23 @@
String userName = options_array[3];
String password = options_array[4];
int querytimeoutvalue = Integer.parseInt(options_array[5]);
- File JarFile = new File(options_array[6]);
- String jarfile_path = JarFile.toURI().toURL().toString();
- StringWriter exception_stack_trace_string_writer = new StringWriter();
- PrintWriter exception_stack_trace_print_writer = new PrintWriter(exception_stack_trace_string_writer);
+
+ exception_stack_trace_string_writer = new StringWriter();
+ exception_stack_trace_print_writer = new PrintWriter(exception_stack_trace_string_writer);
NumberOfColumns = 0;
conn = null;
try
{
+ File JarFile = new File(options_array[6]);
+ String jarfile_path = JarFile.toURI().toURL().toString();
+
if (JDBC_Driver_Loader == null)
{
- JDBC_Driver_Loader = new JDBCDriverLoader(new URL[]{JarFile.toURI().toURL()});
+ /* If JDBC_Driver_Loader is being
+ * created. */
+ JDBC_Driver_Loader = new JDBCDriverLoader(new URL[]{JarFile.toURI().toURL()});
}
else if (JDBC_Driver_Loader.CheckIfClassIsLoaded(DriverClassName) == null)
{
@@ -80,8 +86,6 @@ else if (JDBC_Driver_Loader.CheckIfClassIsLoaded(DriverClassName) == null)
conn = JDBCDriver.connect(url, JDBCProperties);
db_metadata = conn.getMetaData();
- System.out.println("Connection to "+db_metadata.getDatabaseProductName()+" "+db_metadata.getDatabaseProductVersion()
- +" successful.\n");
sql = conn.createStatement(ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_READ_ONLY);
try
@@ -94,6 +98,11 @@ else if (JDBC_Driver_Loader.CheckIfClassIsLoaded(DriverClassName) == null)
}
catch(Exception setquerytimeout_exception)
{
+ /* If an exception occurs,it is returned back to the
+ * calling C code by returning a Java String object
+ * that has the exception's stack trace.
+ * If all goes well,a null String is returned. */
+
setquerytimeout_exception.printStackTrace(exception_stack_trace_print_writer);
return (new String(exception_stack_trace_string_writer.toString()));
}
@@ -106,6 +115,11 @@ else if (JDBC_Driver_Loader.CheckIfClassIsLoaded(DriverClassName) == null)
}
catch (Exception initialize_exception)
{
+ /* If an exception occurs,it is returned back to the
+ * calling C code by returning a Java String object
+ * that has the exception's stack trace.
+ * If all goes well,a null String is returned. */
+
initialize_exception.printStackTrace(exception_stack_trace_print_writer);
return (new String(exception_stack_trace_string_writer.toString()));
}
@@ -125,6 +139,8 @@ else if (JDBC_Driver_Loader.CheckIfClassIsLoaded(DriverClassName) == null)
try
{
+ /* Row-by-row processing is done in jdbc_fdw.One row
+ * at a time is returned to the C code. */
if (result_set.next())
{
for (i = 0; i < NumberOfColumns; i++)
@@ -133,6 +149,11 @@ else if (JDBC_Driver_Loader.CheckIfClassIsLoaded(DriverClassName) == null)
}
++NumberOfRows;
+
+ /* The current row in result_set is returned
+ * to the C code in a Java String array that
+ * has the value of the fields of the current
+ * row as it values. */
return (Iterate);
}
@@ -143,14 +164,15 @@ else if (JDBC_Driver_Loader.CheckIfClassIsLoaded(DriverClassName) == null)
returnresultset_exception.printStackTrace();
}
+ /* All of result_set's rows have been returned to the C code. */
return null;
}
/*
* Close
* Releases the resources used.
*/
- public void
+ public String
Close()
{
@@ -164,16 +186,24 @@ else if (JDBC_Driver_Loader.CheckIfClassIsLoaded(DriverClassName) == null)
}
catch (Exception close_exception)
{
- close_exception.printStackTrace();
+ /* If an exception occurs,it is returned back to the
+ * calling C code by returning a Java String object
+ * that has the exception's stack trace.
+ * If all goes well,a null String is returned. */
+
+ close_exception.printStackTrace(exception_stack_trace_print_writer);
+ return (new String(exception_stack_trace_string_writer.toString()));
}
+
+ return null;
}
/*
* Cancel
* Cancels the query and releases the resources in case query
* cancellation is requested by the user.
*/
- public void
+ public String
Cancel()
{
@@ -184,7 +214,15 @@ else if (JDBC_Driver_Loader.CheckIfClassIsLoaded(DriverClassName) == null)
}
catch(Exception cancel_exception)
{
- cancel_exception.printStackTrace();
+ /* If an exception occurs,it is returned back to the
+ * calling C code by returning a Java String object
+ * that has the exception's stack trace.
+ * If all goes well,a null String is returned. */
+
+ cancel_exception.printStackTrace(exception_stack_trace_print_writer);
+ return (new String(exception_stack_trace_string_writer.toString()));
}
+
+ return null;
}
}
Oops, something went wrong. Retry.

0 comments on commit 7b98541

Please sign in to comment.