Java data calling and Database Calling

Source: Internet
Author: User

Speaking of Java operations on Oracle, We Have To Say JDBC. JDBC is actually a Java database connection. It is a set of interfaces that define interfaces for accessing databases, through JDBC, we can operate Oracle and other databases. In fact, JDBC will be used as long as database operations are involved (the data interface of C language is ODBC ). JDBC has two important packages: Java. SQL and javax. SQL. Pay attention to these two packages when learning to operate databases. The following describes the actual operation process. The key point is the driver and the load driver. There are four methods for the driver, but there are three methods for loading the driver. However, loading programs are usually used only in two ways.

Class. forname () is used to load the driver. There are two loading methods. Class.Forname("Sun. JDBC. ODBC. jdbcodbcdriver"); Class.Forname("Oracle. JDBC. driver. oracledriver "); these two methods have different drivers, the first is the JDBC-ODBC method, and the second is the JDBC Method, this loading method can also be another loading method, Driver
DRV = new Oracle. JDBC. Driver. oracledriver (); drivermanager. registerdriver (DRV ). But in fact, there is not much difference in actual use, because the difference lies in performance.

The subsequent steps are simple: establish a connection, obtain the statement object, execute the SQL statement through the statement object, and obtain the resultset object. The classes that appear in these steps are the key. You can master these classes to master the entire loading process. These classes are respectively connection Class, Class class, resultset class, statement class, And drivermanager. In particular, drivermanager should pay attention to this because it does not generate an object, but directly uses drivermanager to call the method. This design mode uses the singleton mode, however, we only use this method. Therefore, we do not need to reference drivermanager in actual use.

Description of parameters for establishing getconnection (): the first parameter uses the Oracle URL format, JDBC: oracle: thin :( protocol) @ IP Address: Port: the name of the database instance used, the second and third parameters are the database username and password respectively.

In terms of database operations, we should understand that the general language for operations is the SQL language. Therefore, we should master basic functions such as insert, delete, and search.

In Android, there are five Data Storage Methods: SQLite, file, sharedpreferences, network storage, and contentprovider for data storage. However, only SQLite is involved, SQLite is a lightweight embedded database engine. It not only encapsulates the methods for operating databases using the SQL language, but also the methods for operating the database defined by itself. In addition, the database must inherit from itself to add custom features. Similar to operating oracle in Java, this lies in running SQL commands. In addition, SQLite has added many methods and encapsulated them into classes. (Still need to be strengthened)

Openfileinput () is used for data storage. It should be clear that the reason why file is stored is because file exists in openfileinput (), not just openinput (), the file feature is loaded to store data on mobile phone files in inherent attributes.

Sharedpreferences is a lightweight storage class that stores data in the form of key-value pairs. The design mode is a singleton mode. Therefore, the Method Editor () is loaded for data operations. Note that this is the most common application method in the singleton mode. Generally, one class contains another class, and the other class is the key for storing data, its class provides its own methods for operation and management. The Singleton mode is used to ensure the uniqueness of data storage. Therefore, Singleton mode is the best choice. The data is stored in the mobile phone directory.

SQLite is an embedded database of Android, and Oracle database is an external large database, which cannot be embedded in Java or android. Therefore, when using Oracle, you can only use SQL for connection operations, generally, commands are sent to the database for indirect operations (the database is the main body and the database executes the commands we send), which is different from SQLite in this regard. As an embedded database, SQLite itself can be added to a custom method, that is, there is no SQL method. SQLite has two database implementation methods: sqlitedatabase and sqliteopenhelper. In fact, only sqliteopenhelper is used to implement a necessary help class, which itself has a database sqlitedatabase, other methods of this class are operations performed on the database. At the same time, note that this method achieves database operations through indirect database operations. Sqliteopenhelper must implement three methods: constructor, oncreate, onupgrate, and other methods for selective loading. You can think of sqliteopenhelper as a encapsulated class to facilitate database operations (unfinished)

Sharedpreferences, file, and SQLite are all stored in the mobile phone directory. At the same time, you need permissions to operate the resources of your mobile phone, such as the mobile phone directory.

Contentprovider is detailed in another blog.

The Network Data Storage section is described in detail in another blog.

Intent name indicates the purpose, intent, which can be used for page conversion, data transmission, calling external programs, and calling system functions.

(Unfinished: At the same time, we should pay attention to the differences between Java and Android in terms of database calls. However, there are many commonalities that need to be understood to deepen the Java, android calls the database mechanism .)

(Unfinished)

Related Article

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.