querydsl/querydsl-sql/src/test/java/com/mysema/query/ddl/DropTableClause.java
Timo Westkämper 49eae3f6ec Format code
2013-03-19 13:17:12 +02:00

52 lines
1.2 KiB
Java

/*
* Copyright (c) 2010 Mysema Ltd.
* All rights reserved.
*
*/
package com.mysema.query.ddl;
import java.sql.Connection;
import java.sql.SQLException;
import java.sql.Statement;
import com.mysema.query.QueryException;
import com.mysema.query.sql.SQLTemplates;
/**
* DropTableClause defines a DROP TABLE clause
*
* @author tiwe
*
*/
public class DropTableClause {
private final Connection connection;
private final String table;
public DropTableClause(Connection conn, SQLTemplates templates, String table) {
this.connection = conn;
this.table = templates.quoteIdentifier(table);
}
@SuppressWarnings("SQL_NONCONSTANT_STRING_PASSED_TO_EXECUTE")
public void execute() {
Statement stmt = null;
try{
stmt = connection.createStatement();
stmt.execute("DROP TABLE " + table);
} catch (SQLException e) {
// do not rethrow
}finally{
if (stmt != null) {
try {
stmt.close();
} catch (SQLException e) {
throw new QueryException(e);
}
}
}
}
}