20145235 Java Programming 9th Week of study summary

Source: Internet
Author: User

16th Integrated Database JDBC
    • A specification of the Java language to access a database is a set of APIs.
    • The JDBC (Java database Connectivity) API, the Java Databases programming interface, is a standard set of interfaces and classes in the Java language that can be used by Java client programs to access a variety of different types of databases.
    • such as the establishment of database connections, execute SQL statements for data access operations.
    • Register driver operation: The standard way to establish a connection to a database is to call the Drivermanager.getconnection method.
    • The method accepts a string that contains a URL. The DriverManager class, known as the JDBC Management layer, will attempt to find a driver that can connect to the database that the URL represents.
    • The DriverManager class contains a list of registered driver classes. When the method getconnection is called, it checks each driver in the manifest until it finds a driver that can connect to the database specified in the URL.
    • Driver method Connect uses this URL to establish an actual connection.
    • Get connection Action object: To get an operand can be obtained by DriverManager's getconnection ().
    • Close the Connection action object: Use Close () to close the connection to the database, or you can use the attempt to automatically turn off resource syntax to simplify program composition.
Statement
    • Statement's ExecuteQuery () method is the Sql,executeupdate () that is used for querying a database such as SELECT, which returns an int result representing the number of changes in the data, ExecuteQuery () Returns a Java.sql.ResultSet object that represents the result of the query, and the result of the query is a sum of data.
    • You can use ResultSet's next () to move to the next data, which returns TRUE or false to indicate whether there is a next piece of data, and then you can use GETXXX () to get the data. If some of the actions are just some of the parameters in the SQL statement that are different, the rest of the SQL clauses are the same, you can use Java.sql.PreparedStatement.
    • You can use the connection PreparedStatement () method to create good one precompiled (precompile) SQL commands, where the parameters change, specifying "?" first. The placeholder character.
    • When you need to really specify a parameter execution, then use the corresponding Setint (), setString (), and so on, to specify "?" The parameters that should be true.
Reflection and Class Loader
    • Java actually requires a class to load the corresponding. class document, rather than loading all classes at program startup.
    • An instance of Java.lang.Class represents a. class document that is loaded when the Java application runs.
    • The class object corresponding to each object can be obtained through the GetClass () method of object, or through a. Class constant, and if it is a base type, the class object can also be obtained by using the corresponding package classes plus. Type.
    • For example: Integer.type can get a class object representing int.
    • If you do not know the class name beforehand, you can use Class.forName () to dynamically load the. class document, and then use its newinstance () method to build the class instance after the class object is obtained.
    • The Java.lang.reflect.Method instance is the representative object of the method, and you can use the Invoke () method to invoke the specified method dynamically.
Custom generics
    • When you define a generic, you must be a subclass of a class when you specify the actual type of T with the extends qualification.
    • Covariance (covariance): B is a subclass of node that can be thought of as node, which is called node with covariance.
    • wildcard character "? "The type with extends limit T, can only be specified by the name of the T declaration to object, or the name of the T declaration is specified as null.
Custom Enumeration
    • The Enum defines a special class that inherits from Java.lang.Enum.
    • An enum is an abstract class that cannot be instantiated directly.
    • The enum operation comparable interface, and the value of ordinal is the order of the members that use the Enum enumeration. Equals () and hashcode () basically inherit the behavior of object, but are marked as final.
    • You can use the method of values () to return an array of internally maintained action enumeration instances.

20145235 Java Programming 9th Week of study summary

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.