File tree Expand file tree Collapse file tree
src/main/java/io/github/intisy/utils/custom Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -920,4 +920,28 @@ private static String padRight(String s, int n) {
920920 }
921921 return sb .toString ();
922922 }
923+
924+ public boolean tableExists (String tableName ) {
925+ validateIdentifier (tableName );
926+
927+ try {
928+ DatabaseMetaData metaData = getConnection ().getMetaData ();
929+ String catalog = getConnection ().getCatalog ();
930+ String schemaPattern = (databaseType == DatabaseType .MYSQL ) ? catalog : null ;
931+
932+ try (ResultSet tables = metaData .getTables (
933+ catalog ,
934+ schemaPattern ,
935+ tableName ,
936+ new String []{"TABLE" })) {
937+
938+ boolean exists = tables .next ();
939+ logger .debug ("Table '" + tableName + "' " + (exists ? "exists" : "does not exist" ));
940+ return exists ;
941+ }
942+ } catch (SQLException e ) {
943+ logger .error ("Failed to check if table '" + tableName + "' exists: " + e .getMessage ());
944+ throw new RuntimeException (e );
945+ }
946+ }
923947}
You can’t perform that action at this time.
0 commit comments