Table existance
In this chapter you will learn:
Table exists
import java.sql.Connection;
import java.sql.DatabaseMetaData;
import java.sql.DriverManager;
import java.sql.ResultSet;
//j a v a 2s .c o m
public class Main {
public static void main(String[] args) throws Exception {
Connection conn = getHSQLConnection();
DatabaseMetaData md = conn.getMetaData();
ResultSet rs = md.getTables(null, null, "employee", null);
if (rs.next()) {
System.out.println("Table exists");
} else {
System.out.println("Table does not exist");
}
conn.close();
}
private static Connection getHSQLConnection() throws Exception {
Class.forName("org.hsqldb.jdbcDriver");
String url = "jdbc:hsqldb:data/tutorial";
return DriverManager.getConnection(url, "sa", "");
}
}
The code above generates the following result.
Next chapter...
What you will learn in the next chapter:
Home » Java Tutorial » Driver and Connection