Metadata-DataBaseMetaData
Metadata: definitions of databases, tables, and columns.
Connection. getDatabaseMetaData ()
DataBaseMetaData object
GetURL (): returns a String object, representing the URL of the database.
GetUserName (): returns the username used to connect to the current database management system.
GetDatabaseProductName (): returns the product name of the database.
GetDatabaseProductVersion (): returns the database version number.
GetDriverName (): returns the name of the driver.
GetDriverVersion (): returns the driver version number.
IsReadOnly (): returns a boolean value indicating whether the database only supports read operations.
PreparedStatement. getParameterMetaData ()
Obtain the ParameterMetaData object that represents the PreparedStatement metadata.
Select * from user where name =? And password =?
ParameterMetaData object
GetParameterCount ()
Obtain the number of specified parameters
GetParameterType (int param)
Obtain the SQL type of the specified parameter
Metadata-ResultSetMetaData
ResultSet. getMetaData ()
Obtain the ResultSetMetaData object that represents the metadata of the ResultSet object.
ResultSetMetaData object
GetColumnCount ()
Returns the number of columns of the resultset object.
GetColumnName (int column)
Obtains the name of a specified column.
GetColumnTypeName (int column)
Obtains the type of the specified column.
Use metadata to simplify JDBC code
Business Background: All entity objects in the system involve basic CRUD operations:
The CUD operation code of all objects is basically the same, and only the SQL statements sent to the database are different. Therefore, you can extract all the same code of the CUD operation to an update method of the tool class, and define the SQL statement that the parameter receives the change. Www.2cto.com
In addition to different SQL statements, the R operation of an object maps the ResultSet object to different entities. Therefore, you can define a query method, in addition to the SQL statements that receive changes in the form of parameters, the policy mode is used by the caller OF THE qurey method to determine how to map the data in the ResultSet to the object.
Introduction to O-R Mapping
What is O-R Mapping
Commonly used O-R Mapping tools
Hibernate
Ibatis
Commons DbUtils (simple encapsulation of JDBC)