Java Connection getStringFunctions() method with example


The getStringFunctions() method of the Connection interface retrieves the list of String functions supported by the current database. The names returned by this method are the Open CLI String function names.

This method returns a String value holding the list of functions separated by commas (",").

To get the list of the String functions supported by the underlying database −

  • Make sure your database is up and running.
  • Register the driver using the registerDriver() method of the DriverManager class. Pass an object of the driver class corresponding to the underlying database.
  • Get the connection object using the getConnection() method of the DriverManager class. Pass the URL the database and, user name, password of a user in the database, as String variables.
  • Get the DatabaseMetaData object with respect to the current connection using the getMetaData() method of the Connection interface.

Finally, get the list of String functions supported by the underlying database, by invoking the getStringFunctions() method of the DatabaseMetaData class.

Following JDBC program establishes connection with MySQL database and, retrieves the list of String functions supported by the underlying database.

Example

import java.sql.Connection;
import java.sql.DatabaseMetaData;
import java.sql.DriverManager;
import java.sql.SQLException;
import java.util.StringTokenizer;
public class DatabaseMetadata_getStringFunctions {
   public static void main(String args[]) throws SQLException {
      //Registering the Driver
      DriverManager.registerDriver(new com.mysql.jdbc.Driver());
      //Getting the connection
      String url = "jdbc:mysql://localhost/mydatabase";
      Connection con = DriverManager.getConnection(url, "root", "password");
      System.out.println("Connection established......");
      //Retrieving the meta data object
      DatabaseMetaData metaData = con.getMetaData();
      //Retrieving the list of String functions
      String numeric_functions = metaData.getStringFunctions();
      StringTokenizer tokenizer = new StringTokenizer(numeric_functions, ",");
      while(tokenizer.hasMoreElements()) {
         System.out.println(tokenizer.nextToken());
      }
      System.out.println(" ");
   }
}

Output

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

Vikyath Ram
Vikyath Ram

A born rival

Updated on: 30-Jul-2019

184 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements