package com.tyndalehouse.step.dataloader.utils; import java.sql.Connection; import java.sql.PreparedStatement; import java.sql.ResultSet; import java.sql.SQLException; import com.tyndalehouse.step.dataloader.ClientDbProvider; public class DerbyUtils { //TODO: optimize: creating a new connection each time sounds like a waste of time... public static void dropIfExists(String tableName) throws SQLException { //Connection conn = DriverManager.getConnection("jdbc:default:connection"); Connection conn = ClientDbProvider.getConnection(); PreparedStatement exists = conn.prepareStatement("select count(*) from sys.systables where tablename = upper('" + tableName + "')"); ResultSet exRs = exists.executeQuery(); exRs.next(); //get count out: int count = exRs.getInt(1); if(count > 0) { //System.out.println("Dropping table " + tableName); PreparedStatement s = conn.prepareStatement("drop table " + tableName); s.executeUpdate(); } //conn.close(); } }