package org.nhooo.example.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/nhooo"; private static final String USERNAME = "root"; private static final String PASSWORD = ""; public static void main(String[] args) { try (Connection connection = DriverManager.getConnection(URL, USERNAME, PASSWORD)) { DatabaseMetaData meta = connection.getMetaData(); // 获取数据库支持的字符串函数 String[] functions = meta.getStringFunctions().split(",\\s*"); for (String function : functions) { System.out.println("Function = " + function); } } catch (SQLException e) { e.printStackTrace(); } } }
这是MySQL数据库支持的字符串函数的结果:
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依赖
<!-- https://search.maven.org/remotecontent?filepath=mysql/mysql-connector-java/8.0.17/mysql-connector-java-8.0.17.jar --> <dependency> <groupId>mysql</groupId> <artifactId>mysql-connector-java</artifactId> <version>8.0.17</version> </dependency>