11_java _ Cao jianbo 11.27 write your own JDBC framework

Source: Internet
Author: User

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)

 

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.