List the Time and Date Functions Supported by a Database in Java
Description
The following code shows how to list the Time and Date Functions Supported by a Database.
Example
import java.sql.Connection;
import java.sql.DatabaseMetaData;
import java.sql.DriverManager;
import java.util.Arrays;
/*from w w w. j a va 2s . c om*/
public class Main {
public static void main(String[] args) throws Exception {
Connection connection = getConnection();
DatabaseMetaData dbmd = connection.getMetaData();
// Get the list of time and date functions
String timedateFunctions[] = dbmd.getTimeDateFunctions().split(",\\s*");
Arrays.toString(timedateFunctions);
}
private static Connection getConnection() throws Exception {
Class.forName("org.hsqldb.jdbcDriver");
String url = "jdbc:hsqldb:mem:data/tutorial";
return DriverManager.getConnection(url, "sa", "");
}
}