I have a table named test2 in my database. now i want to check if it exists in java code. i have written these lines of code to check if the table exists or not.
DatabaseMetaData dbm = conn.getMetaData();
ResultSet rs = dbm.getTables(null, "APP", "test2", null);
if (!rs.next()) {
PreparedStatement create = conn.prepareStatement("create table test2(name2 varchar(33))");
create.executeUpdate();
}else{
System.out.println("already exists");
}
As test2 exists in APP schema, my else should get executed. but in my case if is getting executed.