HEADLESS_0NE
HEADLESS_0NE

Reputation: 3536

JDBC: Create tables on first use only?

I am working on a Java UI application that uses JDBC. I assume the database I'm working in is already existing. However, the tables the program refers to may not necessarily exist.

Thus, only on first use, I'd like to check if these tables exist, and if not, create them.

Upvotes: 3

Views: 2959

Answers (1)

Fahim Parkar
Fahim Parkar

Reputation: 31627

While creating table say

CREATE TABLE IF NOT EXISTS ......

See this for more information.

CREATE TABLE IF NOT EXISTS Employee (id INT);

This works with mysql, sql, PostgreSQL, Oracle

Upvotes: 4

Related Questions