- Data Structure
- Networking
- RDBMS
- Operating System
- Java
- MS Excel
- iOS
- HTML
- CSS
- Android
- Python
- C Programming
- C++
- C#
- MongoDB
- MySQL
- Javascript
- PHP
- Physics
- Chemistry
- Biology
- Mathematics
- English
- Economics
- Psychology
- Social Studies
- Fashion Studies
- Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Java DatabaseMetaData getMaxColumnsInOrderBy() method with example.
The getMaxColumnsInOrderBy() method of the DatabaseMetaData interface is used to find out the maximum number of columns that the underlying database allows in an ORDER BY clause.
This method returns an integer value, representing the maximum number of columns allowed in an ORDER BY clause. If this value is 0 it indicates that there is no limit or, limit is unknown.
To get the DatabaseMetaData object −
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 maximum number of columns allowed in an ORDER BY clause, by invoking the getMaxColumnsInOrderBy() method (of the DatabaseMetaData interface).
Example
Following JDBC example connects to MySQL database, retrieves and prints the maximum number of columns allowed in an ORDER BY clause, by it.
import java.sql.Connection; import java.sql.DatabaseMetaData; import java.sql.DriverManager; import java.sql.SQLException; public class DatabaseMetadata_getMaxColumnsInOrderBy { 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 maximum number of columns allowed in an ORDER BY clause int maxColumns = metaData.getMaxColumnsInOrderBy(); System.out.println("Maximum number of columns allowed in an ORDER BY clause: "+maxColumns); } }
Output
Connection established...... Maximum number of columns allowed in an ORDER BY clause: 64