Kode Java

Learn Java by Examples

Java

Java

  • Java
    • Basic
    • Core API
    • 2D
    • Applet
    • AWT
    • Date Time
    • Concurrency
    • Cryptography
    • IO
    • Logging
    • Zip and GZIP
    • Reflection
    • Regex
    • JDBC
    • Scripting
    • Beans
    • Mail
    • Security
    • XML
    • Swing
    • HTTP Client
Spring

Spring

  • Spring
    • Spring Core
    • Spring JDBC
Persistence

Persistence

  • Persistence
    • JPA
    • Hibernate
    • MyBatis
Servlet

Servlet

  • Servlet
    • Servlet
    • JSP
    • Taglib
Other Libraries

Other Libraries

  • Other Libraries
    • Apache Commons
    • Apache HttpComponents
    • Apache POI
    • E-iceblue Spire
    • Google Gson
    • iText PDF
    • Jackson
    • Jasypt
    • JDOM
    • Joda-Time
    • jPOS
    • JSch
    • JSON-Java
    • Project Lombok
    • ZK Framework
Patterns

Patterns

  • Patterns
    • Creational Patterns
Android

Android

  • Android
    • Android Misc
Databases

Databases

  • Databases
    • Learning SQL
    • MySQL
    • MongoDB
JVM Languages

JVM Languages

  • JVM Languages
    • Kotlin
Tools

Tools

  • Tools
    • IntelliJ IDEA
    • Gradle
    • JUnit
    • Maven
    • OS X
    • Ubuntu
    • UML

Tag: Function

How do I get system functions supported by database?

By Wayan in JDBC Last modified: July 31, 2023 0 Comment
package org.kodejava.jdbc;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.DatabaseMetaData;
import java.sql.SQLException;

public class SystemFunction {
    private static final String URL = "jdbc:mysql://localhost/kodejava";
    private static final String USERNAME = "kodejava";
    private static final String PASSWORD = "s3cr*t";

    public static void main(String[] args) {
        try (Connection connection =
                     DriverManager.getConnection(URL, USERNAME, PASSWORD)) {
            DatabaseMetaData meta = connection.getMetaData();

            // Get system functions supported by database
            String[] functions = meta.getSystemFunctions().split(",\\s*");

            for (String function : functions) {
                System.out.println("Function = " + function);
            }
        } catch (SQLException e) {
            e.printStackTrace();
        }
    }
}

Here are MySQL database supported system functions.

Function = DATABASE
Function = USER
Function = SYSTEM_USER
Function = SESSION_USER
Function = PASSWORD
Function = ENCRYPT
Function = LAST_INSERT_ID
Function = VERSION

Maven Dependencies

<dependency>
    <groupId>com.mysql</groupId>
    <artifactId>mysql-connector-j</artifactId>
    <version>8.1.0</version>
</dependency>

Maven Central

How do I get date time functions supported by database?

By Wayan in JDBC Last modified: July 31, 2023 0 Comment
package org.kodejava.jdbc;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.DatabaseMetaData;
import java.sql.SQLException;

public class DateTimeFunction {
    private static final String URL = "jdbc:mysql://localhost/kodejava";
    private static final String USERNAME = "kodejava";
    private static final String PASSWORD = "s3cr*t";

    public static void main(String[] args) {
        try (Connection connection =
                     DriverManager.getConnection(URL, USERNAME, PASSWORD)) {
            DatabaseMetaData meta = connection.getMetaData();

            // Get date and time functions supported by database
            String[] functions = meta.getTimeDateFunctions().split(",\\s*");

            for (String function : functions) {
                System.out.println("Function = " + function);
            }
        } catch (SQLException e) {
            e.printStackTrace();
        }
    }
}

Date and time functions supported by MySQL database.

Function = DAYOFWEEK
Function = WEEKDAY
Function = DAYOFMONTH
Function = DAYOFYEAR
Function = MONTH
Function = DAYNAME
Function = MONTHNAME
Function = QUARTER
Function = WEEK
Function = YEAR
Function = HOUR
Function = MINUTE
Function = SECOND
Function = PERIOD_ADD
Function = PERIOD_DIFF
Function = TO_DAYS
Function = FROM_DAYS
Function = DATE_FORMAT
Function = TIME_FORMAT
Function = CURDATE
Function = CURRENT_DATE
Function = CURTIME
Function = CURRENT_TIME
Function = NOW
Function = SYSDATE
Function = CURRENT_TIMESTAMP
Function = UNIX_TIMESTAMP
Function = FROM_UNIXTIME
Function = SEC_TO_TIME
Function = TIME_TO_SEC

Maven Dependencies

<dependency>
    <groupId>com.mysql</groupId>
    <artifactId>mysql-connector-j</artifactId>
    <version>8.1.0</version>
</dependency>

Maven Central

How do I get numeric functions supported by database?

By Wayan in JDBC Last modified: July 31, 2023 0 Comment
package org.kodejava.jdbc;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.DatabaseMetaData;
import java.sql.SQLException;

public class NumericFunction {
    private static final String URL = "jdbc:mysql://localhost/kodejava";
    private static final String USERNAME = "kodejava";
    private static final String PASSWORD = "s3cr*t";

    public static void main(String[] args) {
        try (Connection connection =
                     DriverManager.getConnection(URL, USERNAME, PASSWORD)) {
            DatabaseMetaData meta = connection.getMetaData();

            // Get numeric functions supported by database
            String[] functions = meta.getNumericFunctions().split(",\\s*");

            for (String function : functions) {
                System.out.println("Function = " + function);
            }
        } catch (SQLException e) {
            e.printStackTrace();
        }
    }
}

Here are the numeric functions supported by MySQL database.

Function = ABS
Function = ACOS
Function = ASIN
Function = ATAN
Function = ATAN2
Function = BIT_COUNT
Function = CEILING
Function = COS
Function = COT
Function = DEGREES
Function = EXP
Function = FLOOR
Function = LOG
Function = LOG10
Function = MAX
Function = MIN
Function = MOD
Function = PI
Function = POW
Function = POWER
Function = RADIANS
Function = RAND
Function = ROUND
Function = SIN
Function = SQRT
Function = TAN
Function = TRUNCATE

Maven Dependencies

<dependency>
    <groupId>com.mysql</groupId>
    <artifactId>mysql-connector-j</artifactId>
    <version>8.1.0</version>
</dependency>

Maven Central

How do I get string functions supported by database?

By Wayan in JDBC Last modified: July 31, 2023 0 Comment
package org.kodejava.jdbc;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.DatabaseMetaData;
import java.sql.SQLException;

public class StringFunction {
    private static final String URL = "jdbc:mysql://localhost/kodejava";
    private static final String USERNAME = "kodejava";
    private static final String PASSWORD = "s3cr*t";

    public static void main(String[] args) {
        try (Connection connection =
                     DriverManager.getConnection(URL, USERNAME, PASSWORD)) {
            DatabaseMetaData meta = connection.getMetaData();

            // Get string functions supported by database
            String[] functions = meta.getStringFunctions().split(",\\s*");

            for (String function : functions) {
                System.out.println("Function = " + function);
            }
        } catch (SQLException e) {
            e.printStackTrace();
        }
    }
}

Here are the string functions supported by MySQL database:

Function = ASCII
Function = BIN
Function = BIT_LENGTH
Function = CHAR
Function = CHARACTER_LENGTH
Function = CHAR_LENGTH
Function = CONCAT
Function = CONCAT_WS
Function = CONV
Function = ELT
Function = EXPORT_SET
Function = FIELD
Function = FIND_IN_SET
Function = HEX
Function = INSERT
Function = INSTR
Function = LCASE
Function = LEFT
Function = LENGTH
Function = LOAD_FILE
Function = LOCATE
Function = LOCATE
Function = LOWER
Function = LPAD
Function = LTRIM
Function = MAKE_SET
Function = MATCH
Function = MID
Function = OCT
Function = OCTET_LENGTH
Function = ORD
Function = POSITION
Function = QUOTE
Function = REPEAT
Function = REPLACE
Function = REVERSE
Function = RIGHT
Function = RPAD
Function = RTRIM
Function = SOUNDEX
Function = SPACE
Function = STRCMP
Function = SUBSTRING
Function = SUBSTRING
Function = SUBSTRING
Function = SUBSTRING
Function = SUBSTRING_INDEX
Function = TRIM
Function = UCASE
Function = UPPER

Maven Dependencies

<dependency>
    <groupId>com.mysql</groupId>
    <artifactId>mysql-connector-j</artifactId>
    <version>8.1.0</version>
</dependency>

Maven Central

© 2023 Kode Java - Made in Bali with ❤️ by Wayan Saryada | Privacy Policy.