/*
 * $Log: JdbcUtil.java,v $
 * Revision 1.3  2004-03-26 10:42:42  NNVZNL01#L180564
 * added @version tag in javadoc
 *
 * Revision 1.2  2004/03/25 13:36:07  Gerrit van Brakel <gerrit.van.brakel@ibissource.org>
 * table exists via count(*) rather then via metadata
 *
 * Revision 1.1  2004/03/23 17:16:14  Gerrit van Brakel <gerrit.van.brakel@ibissource.org>
 * initial version
 *
 */
package nl.nn.adapterframework.util;

import java.sql.Connection;
import java.sql.DatabaseMetaData;
import java.sql.ResultSet;
import java.sql.SQLException;

/**
 * Database-oriented utility functions
 * @version Id
 * @author Gerrit van Brakel
 * @since  4.1
 */
public class JdbcUtil {
	public static final String version="$Id: JdbcUtil.java,v 1.3 2004-03-26 10:42:42 NNVZNL01#L180564 Exp $";
	
	private static final boolean useMetaData=false;
	/**
	 * @return true if tableName exists in database in this connection
	 */
	public static boolean tableExists(Connection conn, String tableName ) throws SQLException {
		
		if (useMetaData) {
			DatabaseMetaData dbmeta = conn.getMetaData();
			ResultSet tableset = dbmeta.getTables(null, null, tableName, null);
			return !tableset.isAfterLast();
		} else {
			try {
				String query="select count(*) from "+tableName;
				conn.createStatement().executeQuery(query);
				return true;
			} catch (SQLException e) {
				return false;
			}
		}
	}
}

@@ -23,16 +23,127 @@
 ava,v $%0A
+ * Revision 1.4  2005-08-18 13:36:09  europe%5CL190409%0A * rework using prepared statement%0D%0A * close() finally%0A *%0A
  * Revis
@@ -151,28 +151,28 @@
 on 1.3  2004
--03-
+/03/
 26 10:42:42 
@@ -172,32 +172,60 @@
 :42:42  
-NNVZNL01#L180564
+Johan Verrips %3Cjohan.verrips@ibissource.org%3E
 %0A * adde
@@ -618,16 +618,51 @@
 taData;%0A
+import java.sql.PreparedStatement;%0A
 import j
@@ -711,16 +711,49 @@
 ption;%0A%0A
+import org.apache.log4j.Logger;%0A%0A
 /**%0A * D
@@ -874,16 +874,81 @@
 cUtil %7B%0A
+%09protected static Logger log = Logger.getLogger(JdbcUtil.class);%0A
 %09public 
@@ -1003,46 +1003,44 @@
 v 1.
-3
+4
  200
-4-03-26 10:42:42 NNVZNL01#L180564
+5-08-18 13:36:09 europe%5CL190409
  Exp
@@ -1269,16 +1269,49 @@
 on %7B%0A%09%09%0A
+%09%09PreparedStatement stmt = null;%0A
 %09%09if (us
@@ -1558,49 +1558,272 @@
 %09%09%09%09
-conn.createStatement().executeQuery(query
+log.debug(%22create statement to check for existence of %5B%22+tableName+%22%5D using query %5B%22+query+%22%5D%22);%0A%09%09%09%09stmt = conn.prepareStatement(query);%0A%09%09%09%09log.debug(%22execute statement%22);%0A%09%09%09%09ResultSet rs = stmt.executeQuery();%0A%09%09%09%09log.debug(%22statement executed%22);%0A%09%09%09%09rs.close(
 );%0A%09
@@ -1886,16 +1886,78 @@
  false;%0A
+%09%09%09%7D finally %7B%0A%09%09%09%09if (stmt!=null) %7B%0A%09%09%09%09%09stmt.close();%0A%09%09%09%09%7D%0A
 %09%09%09%7D%0A%09%09%7D

rework using prepared statement close() finally