Issue
In my project we are using hibernate connection and creating the tables .I want create table api calling that time i want check table is there or not status.
I need alternate code for hibernate
Connection c = ...
DatabaseMetaData dbm = c.getMetaData();`enter code here`
// check if "employee" table is there
ResultSet tables = dbm.getTables(null, null, "employee", null);
if (tables.next()) {
// Table exists
}
else {
// Table does not exist
}
Solution
Hibernate gives you access to the underlying JDBC connection with the doWork
method:
session.doWork(new Work() {
@Override
public void execute(Connection connection) throws SQLException {
DatabaseMetaData dbm = connection.getMetaData();
ResultSet tables = dbm.getTables(null, null, "employee", null);
if (tables.next()) {
// ...
}
});
Answered By - Guillaume
Answer Checked By - Timothy Miller (JavaFixing Admin)